.


:




:

































 

 

 

 


printf Java




ғ қ .ұ ң.

public class Test {

/**

* ә

* - Java-ғ.

*/

public static void main (String args[])

{

System.out.println("Hello, world!");

}

}

printf Java

printf() PrintStream, . print() println() PrintStream.

printf :

printf(String format, Object... args)

format , , . .

%4d, d , 4 , , 4, ( 4-) ( ).

, .

System.out.printf("%6d%n%6d%n%6d%n%6d%n%6d%n%6d", 666666, 55555, 4444, 333, 22, 1);

:

%6d%n, %6d , . %6d 666666, %6d 55555 .. %n . %6d, , 6 .

, printf . Object args . . , d, , , java.util.IllegalFormatConversionException. , , .

:

%[argument_index$][flags][width][.precision]conversion

% , .

[argument_index$] , . "1$", "2$" .. . , , .

[flags] . , "+", +, "-" , , . .

[width] , , . .

[.precision] . . . .

conversion , , . d , s , f . .

(conversion) . , . .

2. .

Integer i=675;

double root;

root = Math.sqrt(i);

System.out.println(" " + i + " " + root);

:

675 25.98076211353316

Java. , , .

Integer i=675;

double root;

root = Math.sqrt(i);

System.out.printf(" %d %f", i, root);

%d i, %f root. .

:

675 25,980762

, 6 . , , , :

System.out.printf(" %d %.2f", i, root);

.

.





:


: 2016-11-22; !; : 528 |


:

:

,
==> ...

1786 - | 1769 -


© 2015-2024 lektsii.org - -

: 0.01 .