๋ฐ์ํ
๋ฌธ์์ด์ ํด๋น ๋ณ์์ type์ ํด๋นํ๋ ํฌ๋งท์ ์ ์ด์ฃผ๊ณ ,
๊ทธ ๋ค์๋ ,๋ฅผ ์ฌ์ด์ ๋๊ณ ํ์ํ ๋ณ์๋ฅผ ์์๋๋ก ๋์ดํ๋ ์์ผ๋ก ํฌ๋งท์ ๋ง์ถ ์ ์๋ค.
2๊ฐ ์ด์์ ๋ณ์๋ฅผ ํ ๋ฌธ์์ด์ ๋ฃ๊ธฐ ์ํด์๋ ,๋ฅผ ์ฌ๋ฌ ๊ฐ ์ฌ์ฉํ์ฌ ๋ณ์๋ค์ ์์๋๋ก ๋์ดํ๋ฉด ๋๋ค.
๋ณ์ ํฌ๋งท์ ๋ฌธ์์ด์ ๊ฒฝ์ฐ %s๋ฅผ, ๋ฌธ์์ ๊ฒฝ์ฐ %c๋ฅผ, ์ ์์ ๊ฒฝ์ฐ %d, ์ค์์ ๊ฒฝ์ฐ %f ๋ฑ์ด ๊ฐ๋ฅ
JAVA ์ฝ๋
public class Main {
public static void main (String args[]) {
int a = 5;
System.out.printf("A is %d\n", a);
String b = "apple";
System.out.printf("B is %s\n", b);
System.out.printf("A is %d and B is %s\n", a, b);
}
}
์ถ๋ ฅ๊ฒฐ๊ณผ
A is 5
B is apple
A is 5 and B is apple
๋ฌผ๋ก System.out.print, System.out.println ์ด์ฉํด๋๋จ
JAVA์ฝ๋
public class Main {
public static void main (String args[]) {
int a = 5;
System.out.println("A is " + a);
String b = "apple";
System.out.println("B is " + b);
System.out.println("A is " + a + " and B is " + b);
}
}
์ถ๋ ฅ๊ฒฐ๊ณผ
A is 5
B is apple
A is 5 and B is apple
๋ฐ์ํ
'๐น๏ธ ์ฝ๋ฉํ ์คํธ > ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] ๋๋ฌธ์, ์๋ฌธ์ ๋ณํ (toUpperCase, toLowerCase) (0) | 2024.10.21 |
---|---|
[JAVA] ๋ฌธ์์ด์ ํน์ ๋ฌธ์ ํฌํจ์ํค๊ธฐ/์ค๋ฐ๊ฟ (0) | 2024.08.07 |