0

HOW TO PRINT int and String ? System.out.print("your age is :", 12); the code above take me to an error -_-

6th Aug 2016, 9:49 AM
ounio
ounio - avatar
6 Respostas
+ 1
You're using a comma, which is for formatted prints with % values for arguments. Use + in your case. System.out.print("your age is: " + 12); to do format would be like System.out.printf("your age is: %d", 12); and to Aquarius, you don't need to set the number to a variable for it to work. It's good coding, but not required. Aady, you don't need to add ln unless you want to print separate lines. print works just fine.
6th Aug 2016, 10:02 AM
James
James - avatar
0
because you need to set a variable thats set to your example 12 and then when you do println you put example: System.out.println("Your age is " + age);
6th Aug 2016, 10:04 AM
Aquarius
Aquarius - avatar
0
No variable is required. Comma should be replaced by +, it is a concatenation operator here!
6th Aug 2016, 12:34 PM
Jasbinder Singh
Jasbinder Singh - avatar
0
thanks James
6th Aug 2016, 2:43 PM
ounio
ounio - avatar
0
int a=12; System.out.println("Age="+a);
6th Aug 2016, 5:34 PM
Toffiq Saddique
0
just replace this : int age = 12; System.out.println("your age is : " + age);
7th Aug 2016, 5:25 AM
Mohammad Reza Karimi
Mohammad Reza Karimi - avatar