0
How can I use one time system. Out. Println to get all outputs..
class MyClass { public static void main(String[ ] args) { String name ="David"; int age = 42; double score =15.9; char group = 'Z'; System.out.println(+age); System.out.println(+score); System.out.println(+group); } }
4 ответов
+ 1
You can
System.out.println("Age = " + age + "\nScore = " + score + "\nGroup = " + group);
The + operator concatenates the variables (in this case) to a string that will be printed in the console.
Spaces are not needed between the + but it makes it more readable, also, "\n" prints a newline
To make it look less messy you can also do:
System.out.printf("Age = %d \nScore = %d \nGroup = %c", age, score, group)
That's a printf or print format, where you specify which datatype you want in each position (e.g: %d is int, %c is char, %s is string) and then you put the values at the end, separated by comas, so you have the output string in one side, and the data in the other.
+ 1
Got my problem solved... thanks alvaro
0
I don't understand the question
0
Here I use 3 time system. Out to get all outputs...
Sir how can I use one time system. Out to get name age score and group