Ask your own question, for FREE!
Computer Science 44 Online
OpenStudy (anonymous):

Which of the following statements does not contain an error? I. Scanner in = new Scanner(System.in); II. System.out.print("Please enter your name (first last): "); III. String firstName = in.Next();

OpenStudy (anonymous):

Depends are we looking for syntax errors, or program functionality?

OpenStudy (kainui):

Try to run the code if you have no idea, it's usually the best way to find out.

OpenStudy (anonymous):

Well off the bat in.Next(); will throw an error, the 'N' should be lower-case.

OpenStudy (woodrow73):

When you do: ``` Scanner in = new Scanner(System.in); ``` Using the 'in' object, you can get user input to the program. So doing ``` System.out.println("User, enter a string."); String userInput = in.nextLine(); System.out.println(userInput + " is what the user typed into the program."); ``` Putting (nextLine()) after in. will allow the user to save what they type into the console to a String in the program.

OpenStudy (anonymous):

why can in.next not start with a capital N?

OpenStudy (woodrow73):

as @Algorithmic said, the (next()) method works for user input as well. Java is a case-sensitive language, meaning that you have to get the capitals all in the right spots for it to work. Though it isn't as intimidating as you might think -- there is a method to the madness.. calling a method like .next() or .nextLine(), you can see that the first character is always lower-case in a method, and the first letter of every word after is uppercase... more methods for example: in.nextDouble(); in.nextInt(); in.nextByte(); in.nextShort(); .setToolTipText("This is a longer method for example");

OpenStudy (anonymous):

@woodrow73 refresh my memory methods are "forbidden" from starting with a capitalized letter, that naming convention is reserved for classes, correct?

OpenStudy (woodrow73):

@Algorithmic right "forbidden". You have it right-- methods don't start with a capital letter, and every word in a class starts with an upper case letter. Though nothing is stopping someone from breaking this 'rule' lol.

OpenStudy (anonymous):

thank you guys :)

OpenStudy (woodrow73):

yw

OpenStudy (anonymous):

You are welcome, sorry, I hijacked your thread a tad bit.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!