-2

I've been asking questions about C# and Java because I'm a new programmer, and I was told that the best way to learn is to learn all of the languages at relativley the same time. I've worked with C#, and now I'm on Java, so I'm wondering: What is the Java equivalent of C#'s Console.ReadLine? In C#, I can do this:

 Console.WriteLine("How old are you?");
 int age = Console.ReadLine();

So, how can I do this same basic thing in Java? I'm trying to put many basic lessons together, and I can't find the correct way to do this piece anywhere.

prinsJoe
  • 683
  • 3
  • 7
  • 16
  • 1
    Learn all the languages?! Maybe learn a few at once – Richard Tingle Nov 18 '13 at 23:06
  • Learning all the languages at once seems like a super ambitious idea. Maybe gain some deeper experience with one and then branch out when you have a basic understanding. – Reacher Gilt Nov 18 '13 at 23:34
  • 1
    *I was told that the best way to learn is to learn all of the languages at relativley the same time* Who told you this? – Josh M Nov 19 '13 at 00:23

2 Answers2

3

Use scanner

Scanner s = new Scanner(System.in);
String string = s.nextLine();
Neil Locketz
  • 4,228
  • 1
  • 23
  • 34
1
Scanner input = new Scanner(System.in);
int age = input.nextInt();
Prashant Ghimire
  • 4,890
  • 3
  • 35
  • 46