Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.out.println and String arguments

Tags:

java

println

When I write:

System.out.println("Give grade: ", args[0]);

It gives the error:

The method println(String) in the type PrintStream is not applicable for the arguments (String, String).

Why is this so? However, when I try to write

System.out.println("Give grade :");
System.out.println(args[0]);

No error shows. Is there a way I can write the above in one line of println()?


1 Answers

The two that work only take one parameter, the one that fails takes two. Any chance you have a Javascript or Python background? Java enforces parameter type and count (like C).

Try

System.out.println("Give grade: " + args[0]);

or

System.out.printf("Give grade: %s%n", args[0]);

like image 200
David Ehrmann Avatar answered Oct 24 '25 20:10

David Ehrmann