Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading from console

 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying this but it is not reading properly

System.out.print("Enter Siebel UserId: ");
Scanner scanner = new Scanner(System.in);

String sblUId = scanner.next();

System.out.println(sblUId);

System.out.print("Enter Siebel Password: ");
String sblPwd = scanner.nextLine();

System.out.println(sblPwd);

System.out.print("Enter Inquira UserId: ");
String inqUId = scanner.nextLine();

System.out.println(inqUId);

System.out.print("Enter Inquira Password: ");
String inqPwd = scanner.nextLine();

System.out.println(inqPwd);


Please help
 
Greg Charles
Sheriff
Posts: 2987
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "not reading properly"? You have to give us more to go on than that. What input are you giving it, and what results are you getting? Also, it's a good idea to wrap code in code tags, even when it's relatively simple code like this.
 
Jacob Sonia
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the advice.

Here is the program. Please run it to see what i am telling is the problem

 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jacob Sonia, please read http://faq.javaranch.com/java/TellTheDetails

No one would able to help you till you tell the details. Even without running, I see that you code would not work, because you would get an error in the line 5 something like "Scanner cannot be resolved to a type". Is this your problem?
 
Greg Charles
Sheriff
Posts: 2987
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacob,

Misha is right on both counts. 1. You have to import java.util.Scanner for the program to compile, and 2. you have to explain what problems are having; you can't expect people who are helping you out of the goodness of their hearts to run your programs to figure out your problems for you.

That said, I ran your program anyway. With the addition of that missing import statement, it seems to run fine. What problem are you having?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic