Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2


  1. #1
    Junior Member
    Join Date
    Jul 2013
    Thanked 0 Times in 0 Posts

    Default PLEASE HELP

    Here is my error code:
    Please enter an animal: Now enter another: Exception in thread "main" java.util.NoSuchElementException: No line found
    at java.util.Scanner.nextLine(Scanner.java:
    at strings.main(strings.java:18

    And here is my code:
    import java.util.Scanner ;

    public class Strings {

    public static void main (String[] args) {

    Scanner input1 = new Scanner(System.in);
    Scanner input2 = new Scanner(System.in);
    Scanner input3 = new Scanner(System.in);

    //Get input from user

    System.out.print("Please enter an animal: ");
    String animal1 = input1.nextLine();

    System.out.print("Now enter another: ");
    String animal2 = input2.nextLine();

    System.out.print("One more, please: ");
    String animal3 = input3.nextLine();

    //First manipulation - Print the strings back out

    System.out.println("You entered " + animal1 + ", " + animal2 + ", and " + animal3 + ".") ;

    //Second manipulation - Print the length of the second string

    System.out.println("Your second animal is " + (animal2.length()) + " letters long.") ;

    //Third - Print the first string concatenated with the second

    System.out.println ("Your first and second animals were " + animal1 + ", and " + animal2);

    //Fourth - Print "true" if the first and second strings are the same, false if otherwise

    System.out.print("The first and second animal are the same: ");
    if (animal1==animal2) {
    else {

    //5 - Print out where the first character "c" appears in the first string, -1 if it doesnt

    System.out.println("Where is the letter C in the first animal? Look at letter number " + animal1.indexOf('c')) ;

    //6 - Print out where the third string appears in the second one, or -1

    System.out.println("Where does the third animal appear in the second one?: " + animal2.indexOf(animal3)) ;

    //7 - Print the second string in all capital letters

    System.out.println("YOUR SECOND ANIMAL IN ALL CAPITAL LETTERS IS: " + animal2.toUpperCase() + "!") ;

    //8 - Interpret the third string as an interger, add it to 10, print the result.

    Integer i = Integer.decode("123");
    System.out.println("If your third animal was a number, and I added ten to that number, it would be:" + i+10)

    } //end main
    } //end class

    I'm sure there's a lot of other errors as well, so please point them out! Thank you!

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: PLEASE HELP

    When posting code, please use the highlight tags so we can actually read it.

    Also, please use a more descriptive post title. See the link in my signature on asking questions the smart way.

    Don't compare String with ==. Use the equals() method instead. Search this forum or google for good explanations of why.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!