+ 2
how does the printf work? how to adjust the positions of the output?
i understand that its a print format? not understanding how the syntax works for the output. examples would be great as well thanks.
3 Respuestas
+ 1
im doing a batchelor of it and we are using both printf and System.out.println printf can be used in java to specify the format of the display output.
what i am wondering what are the relevant syntax for the e.g. %n is new line
+ 1
Google the different printf options to learn them all. I'll cover a couple. % essentially is for argument's. %s is for string, %d is decimal, %c is char, etc.. \n is new line, \t is tab. Let's say you have a program that takes 3 numbers and converts them into a time format. You want it to come out like 00:00:00. You'd do System.out.printf("%02d:%02d:%02d", firstnumber, secondnumber, thirdnumber); the 02 is so that it's always in a 2 number format instead of like 1:3:5 you'd get 01:03:05.
0
System.out.print will print in the same line. println in next line.