문자를 입력하세요(Ctrl+z하면 완료)
hey there, wanna hang out? :)
hey there, wanna hang out? :)
알파벳 : 20
숫자 : 0
화이트 : 7
특수문자 : 4
[2] 사용자로부터 두 개의 양수와 연산자를 받아 계산하기
package practice2_Q;
import java.util.Scanner;
public class Q3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("두 개의 양수와 연산자를 입력하세요 : ");
int x = scanner.nextInt();
int y = scanner.nextInt();
String z = scanner.next();
int result = 0;
switch(z){
case "+" : result = x + y; break;
case "-" : result = x - y; break;
case "*" : result = x * y; break;
case "/" : result = x / y; break;
case "%" : result = x % y; break;
default : result = -1;
}
System.out.printf("%d %s %d = %d",x,z,y,result);
scanner.close();
}
}
>> 결과
두 개의 양수와 연산자를 입력하세요 : 2 3 +
2 + 3 = 5
[3] 사용자로부터 알파벳 문자를 하나 받아 나라명 출력하기 (if - else문 활용)
package practice2_Q;
import java.io.IOException;
public class Q4 {
public static void main(String[] args) throws IOException {
String[] nation = {"America","Bangladesh", "Canada", "Demmark","Ezypt", "France",
"Greece","Hungary","Iceland","Jamaica","Korea",
"Lebanon","Malta","North Korea","Oman","Peru","Qatar","Romania","Singapore",
"Thailand","Uganda","Vietnam","W로 시작하는 나라는 없습니다.","X로 시작하는 나라는 없습니다.","Yemen","Zambia"};
String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
System.out.print("문자 한 개를 입력하세요. >> ");
int ch = System.in.read();
//소문자 -> 대문자
if(ch >= 'a' || ch <= 'z') ch -= 32;
for(int i = 0; i < alpha.length(); i++) {
if(ch == alpha.charAt(i)) {
System.out.printf("%c로 시작하는 나라는 : %s",ch,nation[i]);
}
}
}
}
>> 결과
문자 한 개를 입력하세요. >> a
A로 시작하는 나라는 : America
3. 사칙연산 결과를 테이블 형식으로 출력
[1] 정상가격과 세일가격(30%) 출력하기 (정상가격 범위 : 20000원~30000원)
package practice2_Q;
public class Q5 {
public static void main(String[] args) {
System.out.println("정상가격 세일가격");
System.out.println("--------------------------");//14
for(int price = 20000; price <= 30000; price+=1000) {
System.out.printf("%-13d %.0f\n",price,price*0.7);
}
}
}
package practice2_Q;
import java.util.Scanner;
public class Q6 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("양수 n : ");
int n = scanner.nextInt();
int sum = 0;
for(int i = 1; i <= n; i++) {
sum += i;
}
System.out.println("sum : "+sum);
scanner.close();
}
}
>> 결과
양수 n : 5
sum : 15
[3] 1부터 10까지 양의 정수 중 짝수의 곱을 구하기
package practice2_Q;
public class Q7 {
public static void main(String[] args) {
int n = 10;
int result = 1;
for(int i = 1; i <= n; i++) {
if(i % 2 == 0)
result = result * i;
}
System.out.println("result : "+result);
}
}
>> 결과
result : 3840
[4] 원주율을 구하는 공식에 따라 원주율 값 구하기
4/1 - 4/3 + 4/5 - 4/7 + 4/9 .....
package practice2_Q;
public class Q8 {
public static void main(String[] args) {
int n = 1;
int sign = 1;
double result = 0;
for(long i = 0; i < 2000000000; i++) {
result += sign*(4.0/n);
sign = -sign;
n += 2;
}
System.out.println("PI = "+result);
}
}
>> 결과
PI = 3.141592658505181
4. 제곱과 팩토리얼
[1] (제곱) 0~6까지의 제곱과 세제곱을 구하여 테이블 형식으로 출력
package practice2_Q;
public class Q9 {
public static void main(String[] args) {
System.out.println("기존 제곱 세제곱");
System.out.println("-----------------------------");
for(int i = 0; i < 7; i++) {
System.out.printf("%-10d%-10d%d%n",i,i*i,i*i*i);
}
}
}
[2] (팩토리얼) 사용자에게 양의 정수 n을 받아, n! 구하기 (n! = n * (n-1)! // 단, 0!은 1이다)
package practice2_Q;
import java.util.Scanner;
public class Q10 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("n값 : ");
long n = scanner.nextInt();
long result = 1;
//f(x) = x * f(x-1)
//단, x가 0일 때 값은 1이다.
if(n == 0) {
result = 1;
}else {
for(long i = n; i > 0; i--) {
result = result * i;
}
}
System.out.printf("%d! = %d",n,result);
scanner.close();
}
}
팩토리얼은 고등수학에서 순열과 조합을 배우면서 배우는 것인데, 경우의 수를 구할 때 사용한다. 원리는 다음과 같다. 만약 A,B,C 세 사람이 앉는 순서를 정한다 할 때 경우의 수는 아래처럼 구할 수 있다. 0!이 1인 이유는, 아무것도 없을 때에 "없다"는 것도 하나의 경우에 해당하기 때문
[3] 실수의 거듭 제곱 값 구하기 (실수 : r, 정수 : n)
package practice2_Q;
import java.util.Scanner;
public class Q11 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("실수, 정수를 하나씩 입력하세요.(ex.5.34 7)");
double r = scanner.nextDouble();
int n = scanner.nextInt();
double result = 1;
for(int i = 0; i < n; i++) {
result = result * r;
}
System.out.printf("%f^%d = %f",r,n,result);
scanner.close();
}
}
>> 결과
실수, 정수를 하나씩 입력하세요.(ex.5.34 7)
5.231 3
5.231000^3 = 143.137741
package practice;
public class dan99TestBasic {
public static void main(String[] args) {
for(int i = 2; i <= 9; i++) {
System.out.println("--------["+i+"단 시작]--------");
for(int j = 1; j <= 9; j++) {
System.out.printf("%d x %d = %2d%n",i,j,i*j);
}
}
}
}
>> 결과
--------[2단 시작]--------
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
--------[3단 시작]--------
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
--------[4단 시작]--------
4 x 1 = 4
4 x 2 = 8
4 x 3 = 12
4 x 4 = 16
4 x 5 = 20
4 x 6 = 24
4 x 7 = 28
4 x 8 = 32
4 x 9 = 36
--------[5단 시작]--------
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
--------[6단 시작]--------
6 x 1 = 6
6 x 2 = 12
6 x 3 = 18
6 x 4 = 24
6 x 5 = 30
6 x 6 = 36
6 x 7 = 42
6 x 8 = 48
6 x 9 = 54
--------[7단 시작]--------
7 x 1 = 7
7 x 2 = 14
7 x 3 = 21
7 x 4 = 28
7 x 5 = 35
7 x 6 = 42
7 x 7 = 49
7 x 8 = 56
7 x 9 = 63
--------[8단 시작]--------
8 x 1 = 8
8 x 2 = 16
8 x 3 = 24
8 x 4 = 32
8 x 5 = 40
8 x 6 = 48
8 x 7 = 56
8 x 8 = 64
8 x 9 = 72
--------[9단 시작]--------
9 x 1 = 9
9 x 2 = 18
9 x 3 = 27
9 x 4 = 36
9 x 5 = 45
9 x 6 = 54
9 x 7 = 63
9 x 8 = 72
9 x 9 = 81
[1-2] 사용자가 입력한 x단의 구구단을 출력하라_do_while 활용
(단, 사용자는 여러 번 구구단을 입력하고 결과를 받을 수 있어야 한다.)
package practice;
import java.util.Scanner;
public class Dan99Test2 {
public static void main(String[] args) {
int dan = 0;
String yn = "Y";
Scanner scanner = new Scanner(System.in);
do
{
System.out.print("단 입력(2~9단 중 하나) : ");
dan = scanner.nextInt();
if(dan >= 2 && dan <= 9) {
for(int i = 1; i <=9; i++) {
System.out.printf("%d x %d = %2d\n",dan,i,dan*i);
}
System.out.print("더 하시겠습니까? (y/n) :");
yn = scanner.next();
}else {
System.out.println("2~9 중 하나를 입력해주세요.");
}
}while(yn.equals("Y") || yn.equals("y"));
scanner.close();
}
}
>> 결과
단 입력(2~9단 중 하나) : 3
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
더 하시겠습니까? (y/n) :n
- 제어문이란? Control Statement, 프로그램의 흐름(fow)을 바꾸어주는 명령문
제어문
코드
내용
조건문
if, if-else
제한을 두거나 범위를 지정하여 선택
switch-case
다차원 선택 (조건식에 따라 여러개의 결과값으로 이동, 명령 수행)
반복문 (Loop)
for
반복 횟수를 알 때 주로 사용
while
반복 횟수를 모를 때 (화일 처리/키보드입력)
do while
반복 횟수를 모르고, 특정 명령 수행 후 지속여부 확인 후 반복 시 사용
기타
break
switch-case 또는 반복문에서 종료 역할. //제어문 밖으로
continue
반복문에서만 사용 가능 //반복문의 끝으로 이동
return
* 객체지향에서 다루는 제어자(motifier)와는 다르다.
* printf의 제어문자 \n, \r... 는 다른 말로 이스케이프라고 하고, 위 제어문과 다르다.
(프로그래밍 문법을 번역할 때 '제어'를 붙이는 경우가 참 많은 것 같은데... ;; 그럴 땐 원어를 보면 될 것 같다.)
1. 조건문 - if, switch
조건문은 말 그대로 알고리즘 내에 [조건]을 걸어 선택을 할 때 사용 - if문, if-else - switch : 다차원 선택
1) If문
(1) if문 예제_명령프롬프트에서 받은 숫자 확인
package practice;
public class PromptTest {
public static void main(String[] args) {
String input = args[0];
int num = Integer.parseInt(input);
if(num == 0) {
System.out.println("입력한 숫자는 0입니다.");
}
if(num != 0) {
System.out.println("입력한 숫자는 0이 아닙니다.");
}
}
}
>> 결과 (argument : 3)
입력한 숫자는 0이 아닙니다.
(2) if - else문
- 자바는 자바스크립트와 달리 else if문이 없다.
- if - else문 안에 중첩된 if-else문이 마치 else if문처럼 보이는 것..
2) else안에 : if(kor>=93), if(kor>=90)......이 들어있는 것과 같음.
(3) 중첩 if문에서 코드를 간결히 하기 _ 위의 원리를 알면 아래와 같이 &&로 일일히 범위 지정을 하지 않을 수 있다.
package mymain;
import java.util.Scanner;
public class _02_Ex_if3 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int kor; //나의 국어점수
//String grade="ABCDF"; //등급
char result = 'F'; //결과(나의 등급)
System.out.print("국어 : ");
kor = scanner.nextInt();
//효율적 코드
//방법 1)
/*
if(kor>=90 && kor <= 100)
result = grade.charAt(0);
else if(kor>=80 && kor <90)
result = grade.charAt(1);
else if(kor>=70 && kor <80)
result = grade.charAt(2);
else if(kor>=60 && kor <70)
result = grade.charAt(3);
*/
//방법 2)
//유효범위를 먼저 체크(0~100)
if(kor>=0 && kor<=100)
{
if(kor>=90) result = 'A';
else if(kor>=80) result = 'B';
else if(kor>=70) result = 'C';
else if(kor>=60) result = 'D';
//else grade = 'F';
}
else
{
System.out.printf("입력된 점수 [%d]는 유효하지 않습니다.",kor);
}
System.out.printf("국어점수 : %d(점) --> 등급 : %c\n",kor,result);
scanner.close();
}
}
2) switch문
- 다차원 선택 - break를 걸지 않으면 내 case의 명령 이후에, 다음 case의 명령, 그 다음 case의 명령.... 수행
- 로그인한 사용자의 등급을 체크하여 권한을 부여하는 코드
//break를 안 쓰면 grantDelete()부터 아래까지 명령 하나씩 실행
//level 2면, grantWrite(), grantRead() 실행
switch(level){
case 3 : grantDelete();
case 2 : grantWrite();
case 1 : grantRead();
}
- 계절 예제
package mymain;
import java.util.Scanner;
public class _04_Ex_switch2_계절구하기 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int month;
String season = "";
System.out.print("월 : ");
month = scanner.nextInt();
//유효성 검사
if(month >= 1 && month <= 12) {
//계절 구하기__방법1
switch(month)
{
case 3: case 4: case 5: season="봄"; break;
case 6: case 7: case 8: season="여름"; break;
case 9: case 10: case 11: season= "가을"; break;
default : season="겨울";
}
}else {
System.out.println("월은 1~12사이 값을 입력하세요.");
}
System.out.printf("[%d월]의 계절은 [%s]입니다.",month,season);
scanner.close();
}
}
- 학점 내기 예제_ switch의 조건식에서 연산자 /를 통해 몫을 구함
package mymain;
import java.util.Scanner;
public class _05_Ex_switch3_문제 {
public static void main(String[] args) {
//1.국어점수 입력받는다.
//2. switch문을 이용해서 등급을 산출하세요.(ABCDF)--수식활용(10배)
Scanner scanner = new Scanner(System.in);
System.out.print("국어 점수 : ");
int score = scanner.nextInt();
char grade = 'F';
//유효성 확인
if(score>=0 && score<=100) {
//등급내기
switch(score/10)
{
case 10 :
case 9 : grade = 'A'; break;
case 8 : grade = 'B'; break;
case 7 : grade = 'C'; break;
case 6 : grade = 'D'; break;
default : grade = 'F';
}
System.out.printf("[%d]점일 때, 등급은 [%c]입니다.",score,grade);
}else {
System.out.println("유효하지 않은 값입니다.(0~100사이)");
}
scanner.close();
}
}
- 가위바위보 예제
package practice;
import java.util.Scanner;
public class SwitchTest {
public static void main(String[] args) {
//가위(1) 바위(2) 보(3)
String[] optArr = {"","가위","바위","보"};
Scanner scanner = new Scanner(System.in);
System.out.print("가위(1), 바위(2), 보(3) 중 하나 선택 : ");
int user_num = scanner.nextInt();
int comp_num = (int)(Math.random()*3)+1;
if(user_num==1 || user_num==2 || user_num ==3) {
switch(user_num - comp_num) {
case -2 : case 1 :
System.out.printf("당신 : [%s] vs 컴퓨터 : [%s] = 당신의 승!\n", optArr[user_num], optArr[comp_num]);
break;
case -1 : case 2 :
System.out.printf("당신 : [%s] vs 컴퓨터 : [%s] = 비겼네요.\n", optArr[user_num], optArr[comp_num]);
break;
default :
System.out.printf("당신 : [%s] vs 컴퓨터 : [%s] = 졌네요.ㅠㅠ\n", optArr[user_num], optArr[comp_num]);
}
}else {
System.out.println("잘못 입력했습니다.");
}
scanner.close();
}
}
>> 결과
가위(1), 바위(2), 보(3) 중 하나 선택 : 3
당신 : [보] vs 컴퓨터 : [가위] = 졌네요.ㅠㅠ
2. for/while/do-while
- for 문 : 반복횟수를 알 때 - while 문 : 반복횟수를 모를 때(화일처리/키보드입력) pf. 파일 처리의 경우 --> 사용자가 file을 선택하여 읽을 것 --> 개발자는 file에 몇개의 글자수가 있을지 모른다. --> 이럴 경우, while문으로 file의 끝까지 읽어라 명령
1) for문
for문은 반복횟수를 알고 있을 때 사용하기 용이하다.
(1) for문
- 양의 정수의 합 구하기 : 1+2+3+...+num
package practice;
public class SumTest {
public static void main(String[] args) {
int num = 10;
int sum = 0;
for(int i = 1; i <= num; i++)
{
sum += i;
}
System.out.println("sum : "+sum);
}
}
>> 결과
sum : 55
- 짝수의 합 구하기 : 2+4+...+num / 1+3+...+num
package practice;
public class EvenOdd {
public static void main(String[] args) {
int num = 20;
int sum = 0;
//짝수의 합 구하기
//방법1 _ if문 활용
//두번째 차례만 출력 : 1 (2) 3 (4) 5 (6)
for(int i = 0; i <= num; i++)
{
if(i % 2 == 0)
{
sum += i;
}
}
System.out.println("sum : "+sum);
sum = 0;
//방법2 _ for문 내 증감식 활용
//증감을 +2씩 : 2 4 6 8 10
for(int i = 0; i <= num; i+=2)
{
sum += i;
}
System.out.println("sum : "+sum);
}
}
>> 결과
sum : 110
sum : 110
- 'A'부터 'Z'까지 문자 출력하기
(1) ASCII 코드 A : 65, Z : 90, a : 97임을 활용 pf. int ch = 'A'; 가 가능한 이유는? char은 JAVA에서 2byte이며, int는 4byte. 더 큰 타입으로는 자동 형변환 (2) System.out.printf의 형식지정자(formatter) %c 활용 - System.out.printf("%c",65); 의 결과는 'A' - System.out.printf("%d",'A'); 는 안 됨 **why? 그렇게 메서드가 정의되어 있음. (외울 때 Tip. 출력은 디코딩이니 'A' -> %d는 안되는 걸로)
package practice;
public class CharTest {
public static void main(String[] args) {
//A부터 Z까지 출력
//Ascii에서 A : 65, Z : 90, a : 97
//방법1_아스키 10진수 직접 입력
for(int i = 65; i <= 90; i++) {
System.out.printf("%c",i);
}
System.out.println();
//방법2_Char to Int 자동 형변환
for(int i = 'A'; i <= 'Z'; i++) {
System.out.printf("%c",i);
}
System.out.println();
}
}
package practice;
public class BlockTest {
public static void main(String[] args) {
int col = 5;
int row = 5;
for(int i = 0; i < row; i++) {
for(int j = 0; j < col; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
>> 결과
*****
*****
*****
*****
*****
- 반 피라미드 블럭 쌓기
package practice;
public class BlockTest2 {
public static void main(String[] args) {
int row = 5;
for(int i = 0; i < row; i++) {
for(int j = 0; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
>> 결과
*
**
***
****
*****
2) While문
- 반복횟수 모를 때에(파일 처리/키보드입력)
- 파일 읽기
(가정) 프로젝트 폴더에 "test.txt"에 아래와 같이 적었다고 가정
Hello, my love
package practice;
import java.io.FileReader;
import java.io.IOException;
public class FileTest {
public static void main(String[] args) throws IOException, InterruptedException {
//파일을 읽어볼 때
//io안의 클래스 FileReader
//메서드 read() - 파일읽기, close() - 파일닫기
FileReader file = new FileReader("test.txt");
int ch = 0;
int cnt = 0;
//파일을 문자가 없을 때까지 한 문자씩 반복해서 읽고 출력
//**몇개의 문자가 있을지 모른다.
while(true)
{
ch = file.read();
if(ch == -1) break; //문자없을 때 반복문 나가기
System.out.printf("%c",ch);
Thread.sleep(100);
cnt++;
}
System.out.println("\n-----------------------");
System.out.println("총 문자 수 : "+cnt);
file.close();
}
}
>> 결과
Hello,
my love
-----------------------
총 문자 수 : 15
- 반복횟수 모를 때에 용이 - 특정 명령을 행한 뒤(do), (사용자의 의사에 따라) 지속할 지 확인(confirm) 후 반복할 때 사용.
package practice;
import java.util.Scanner;
public class Dan99Test {
public static void main(String[] args) {
int dan = 0;
String yn = "Y";
Scanner scanner = new Scanner(System.in);
do
{
System.out.print("단 입력(2~9단 중 하나) : ");
dan = scanner.nextInt();
if(dan >= 2 && dan <= 9) {
for(int i = 1; i <=9; i++) {
System.out.printf("%d x %d = %2d\n",dan,i,dan*i);
}
System.out.print("더 하시겠습니까? (y/n) :");
yn = scanner.next();
}else {
System.out.println("2~9 중 하나를 입력해주세요.");
}
}while(yn.equals("Y") || yn.equals("y"));
scanner.close();
}
}
>> 결과
단 입력(2~9단 중 하나) : 10
2~9 중 하나를 입력해주세요.
단 입력(2~9단 중 하나) : 3
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
더 하시겠습니까? (y/n) :n
//Tilde ~ : 2진수로 표현했을 때의 1의 보수
class Tilde{
public static void main(String[] args){
int n = 10;
System.out.printf("[%32s]\n",Integer.toBinaryString(n));
System.out.printf("[%32s]\n",Integer.toBinaryString(~n));
}
}
>> 결과
[ 1010]
[11111111111111111111111111110101]
(2) ! : 일반논리 Not연산자
class NotOperator{
public static void main(String[] args){
boolean bOk = !(3>2); //boolean bOk = !3>2; 는 불가 why? 일반논리일 경우에만 !사용 가능
//(3>2) == true
System.out.printf("!(3>2) : %b\n",bOk);
System.out.printf("!true : %b\n",!true);
}
}
>> 결과
!(3>2) : false
!true : false
(3) ++(증가), --(감소) : 증감 연산자
- 전위형 : ++n --> 산술연산, 명령이 있기 전에 먼저 변수값을 +1한다. (먼저 변수값을 +1)
- 후위형 : n++ --> 산술연산, 명령이 있은 후에 변수값을 +1한다. (마지막에 변수값을 +1)
public class PlusplusOperator {
public static void main(String[] args) {
int x = 1;
int y = 2;
int z;
z = ++x + y++;
System.out.printf("x : %d, y : %d, z : %d\n",x,y,z);
}
}
>> 결과
x : 2, y : 3, z : 4
//z = ++x + y++; 의 연산 순서
//1) ++x --- > x = x + 1; //2
//2) x + y --- > 2 + 2
//3) z = x + y --- > z = 4;
//4) y++ --- > y = y + 1; //3
(4) -(부호) : (-1)을 곱해주는 연산자
(5) 강제 형변환 연산자 : cast 연산자
Casting
1. 자동 형변환 1) 연산시 : 자료형이 큰 쪽으로 자동 형변환 2) 대입시 : '='를 기준으로 좌변항이 더 큰 자료형일 경우 좌변형의 자료형으로 자동 형변환
package mymain;
import java.util.Scanner;
public class _08_일반논리연산자응용2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
int year;
System.out.print("연도 : ");
year = scanner.nextInt();
//윤년/평년
//윤년 조건
//조건1. 400의 배수가 되는 해 (ex.400년, 800년...2000년)
//또는
//조건2. 4의 배수이면서 100의 배수가 아닌 해
if((/*조건 1*/year%400==0) || (/*조건2*/year%4==0 && year%100!=0)) {
System.out.printf("[%d]년도는 [윤년]입니다.\n",year);
}else {
System.out.printf("[%d]년도는 [평년]입니다.\n",year);
}
scanner.close();
}
}
>> 결과
연도 : 2022
[2022]년도는 [평년]입니다.
7. 삼항 연산자 : (조건) ? 값(참) : 값(거짓)
class threeOperator{
public static void main(String[] args){
int x = 10;
int y = 4;
String z;
z = (x % y ==0)? "맞다" : "아니다";
System.out.printf("%d는 %d의 배수가 %s", x, y, z);
}
}