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); } }

16th Sep 2019, 11:21 AM
Usman Zafar
Usman Zafar - avatar
4 Answers
+ 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.
16th Sep 2019, 11:51 AM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar
+ 1
Got my problem solved... thanks alvaro
16th Sep 2019, 12:00 PM
Usman Zafar
Usman Zafar - avatar
0
I don't understand the question
16th Sep 2019, 11:43 AM
alvaro.pkg.tar.zst
alvaro.pkg.tar.zst - avatar
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
16th Sep 2019, 11:46 AM
Usman Zafar
Usman Zafar - avatar