Beginning Java question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Beginning Java question

In my code I keep getting errors. What am I doing wrong? public class Program { public static void main(String[] args) { } } // This is a practive run for Java. This is my very first Java Program String name =console.readLine("What is your name?"); String age = console.readLine("What is your age?"); console.printf("user is %s and their name is %s" name, age);

4th May 2019, 10:13 PM
Markie Alicia
Markie Alicia - avatar
9 Answers
+ 3
Denise Roßberg, it works if you run it from command line (eg on desktop OS), where console is open, not in Sololearn environment. (You can test return value for null to avoid error) I think standard PrintStream in System.out you can redirect eg to file or printer, and then you can use console for specific output like service message to user who operate program. Same for standard input
5th May 2019, 6:49 AM
zemiak
+ 5
Looks like there is a comma missing before " name" in the last line.
4th May 2019, 10:27 PM
Thoq!
Thoq! - avatar
+ 3
4th May 2019, 11:32 PM
Denise Roßberg
Denise Roßberg - avatar
4th May 2019, 11:36 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
import java.io.Console; public class Main { public static void main(String[] args) { Console console = System.console(); String name = console.readLine("What is your name? "); String age = console.readLine("What is your age? "); console.printf("user is %s and their name is %s", name, age); } }
5th May 2019, 12:53 AM
zemiak
+ 2
Thank you so much everyone!
5th May 2019, 6:28 PM
Markie Alicia
Markie Alicia - avatar
+ 2
Markie Alicia Your welcome. Happy coding :)
5th May 2019, 6:34 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
5th May 2019, 1:00 AM
Denise Roßberg
Denise Roßberg - avatar
5th May 2019, 1:02 AM
Denise Roßberg
Denise Roßberg - avatar