찾으려면 ctrl+F한 뒤 class이름을 검색하자

각 calss밑에는 실행 시 나오는 console내용이 있다.

public class FlowEx01 {
	public static void main(String[] args) {
		int x = 0;
		System.out.printf("x=%d 일 때, 참인 것은%n", x);

		if (x == 0)
			System.out.println("x==0");
		if (x != 0)
			System.out.println("x!=0"); // f
		if (!(x == 0))
			System.out.println("!(x==0)"); // f
		if (!(x != 0))
			System.out.println("!(x!=0)");

		x = 1;
		System.out.printf("x=%d 일 때, 참인 것은 %n", x);

		if (x == 0)
			System.out.println("x==0"); // f
		if (x != 0)
			System.out.println("x!=0");
		if (!(x == 0))
			System.out.println("!(x==0)");
		if (!(x != 0))
			System.out.println("!(x!=0)"); // f

		if (true) {
			System.out.println("");
		}
	}
}
x=0 일 때, 참인 것은
x==0
!(x!=0)
x=1 일 때, 참인 것은 
x!=0
!(x==0)

 

 

public class FlowEx02 {
	public static void main(String[] args) {
		int input;

		System.out.print("숫자를 하나 입력하세요.>");

		Scanner scanner = new Scanner(System.in);
		String tmp = scanner.nextLine();
		input = Integer.parseInt(tmp);

		if (input == 0) {
//			System.out.println("입력하신 숫자는 0입니다.");
			System.out.println("입력하신 숫자는 0입니다.");
		}

		else if (input % 2 == 0) {
			System.out.println("입력하신 숫자는 짝수입니다.");
		}

		else if (input % 2 == 1) {
			// System.out.println("입력하신 숫자는 0이 아닙니다.");
//		System.out.printf("입력하신 숫자는 %d입니다.", input);
			System.out.println("입력하신 숫자는 홀수입니다.");

			scanner.close();
		}
	}
}
0입력시

숫자를 하나 입력하세요.>0
입력하신 숫자는 0입니다.
숫자를 하나 입력하세요.>1
입력하신 숫자는 홀수입니다.

 

 

public class FlowEx03 {
	public static void main(String[] args) {
		System.out.println("숫자를 하나 입력하세요.>");
		
		Scanner scanner = new Scanner(System.in);
		int input = scanner.nextInt();
		
		if(input==0) {
			System.out.println("입력하신 숫자는 0입니다.");
		} else {
			System.out.println("입력하신 숫자는 0이 아닙니다.");
		}
		scanner.close();
	}
}
숫자를 하나 입력하세요.>
1
입력하신 숫자는 0이 아닙니다.

 

 

public class FlowEx04 {
	public static void main(String[] args) {
		int score = 0;
		char grade = ' ';

		System.out.print("점수를 입력하세요.>");
		Scanner scanner = new Scanner(System.in);
		score = scanner.nextInt();

		if (score >= 90) {
			grade = 'A';
		} else if (score >= 80) {
			grade = 'B';
		} else if (score >= 70) {
			grade = 'C';
		} else {
			grade = 'D';
		}


		System.out.println("당신의 학점은 "+ grade +"입니다.");
		scanner.close();
	}
}
점수를 입력하세요.>30
당신의 학점은 D입니다.

 

 

public class FlowEx05 {
	public static void main(String[] args) {
		int score = 0;
		char grade = ' ', opt = '0';

		System.out.print("점수를 입력해주세요.>");

		Scanner scanner = new Scanner(System.in);
		score = scanner.nextInt();

		System.out.printf("당신의 점수는 %d입니다.%n", score);

		if (score >= 90) {
			grade = 'A';
			if (score >= 98) {
				opt = '+';
			} else if (score < 94) {
				opt = '-';
			}
		} else if (score >= 80) {
			grade = 'B';
			if (score >= 88) {
				opt = '-';
			}
		} else {
			grade = 'C';
		}
		System.out.printf("당신의 학점은 %c%c입니다.%n", grade, opt);
		scanner.close();
	}
}
점수를 입력해주세요.>85
당신의 점수는 85입니다.
당신의 학점은 B0입니다.

 

 

public class FlowEx06 {
	public static void main(String[] args) {
		System.out.println("현재 월을 입력하세요.>");
		
		Scanner scanner = new Scanner(System.in);
		int month = scanner.nextInt();
		
		switch(month) {
		case 3:
		case 4:
		case 5:
			System.out.println("현재의 계절은 봄입니다.");
			break;
		case 6: case 7: case 8:
			System.out.println("현재의 계절은 여름입니다.");
			break;
		case 9: case 10: case 11:
			System.out.println("현재의 계절은 가을입니다.");
			break;
			default:
			case 12: case 1: case 2:
				System.out.println("현재의 계절은 겨울입니다.");
		}
		scanner.close();
	}// main의 끝
}
현재 월을 입력하세요.>
7
현재의 계절은 여름입니다.

 

 

public class FlowEx07 {
	public static void main(String[] args) {
		System.out.print("가위(1),바위(2),보(3) 중 하나를 입력하세요.>");
		
		Scanner scanner = new Scanner(System.in);
		int user = scanner.nextInt();
		int com = (int)(Math.random() * 3) +1;
		
		System.out.println("당신은 "+ user +"입니다.");
		System.out.println("컴은 "+ com +"입니다.");
		
		switch(user-com) {
		case 2: case -1:
			System.out.println("당신이 졌습니다.");
			break;
		case 1: case -2:
			System.out.println("당신이 이겼습니다.");
			break;
		case 0:
			System.out.println("비겼습니다.");
			break;
		}
		scanner.close();
	}//main의 끝
}
가위(1),바위(2),보(3) 중 하나를 입력하세요.>1
당신은 1입니다.
컴은 1입니다.
비겼습니다.

 

 

public class FlowEx08 {
	public static void main(String[] args) {
		System.out.println("당신의 주민번호를 입력하세요. (011231-1111222)>");
		
		Scanner scanner = new Scanner(System.in);
		String regNo = scanner.nextLine();
		
		char gender = regNo.charAt(7);
		
		switch(gender) {
		case '1': case '3':
			System.out.println("당신은 남자입니다.");
			break;
		case '2': case '4':
			System.out.println("당신은 여자입니다.");
			break;
			default:
				System.out.println("유효하지 않은 주민등록번호입니다.");
		}
		scanner.close();
	}// main의 끝

}
당신의 주민번호를 입력하세요. (011231-1111222)>
830721-1351228
당신은 남자입니다.

 

public class FlowEx09 {
	public static void main(String[] args) {
		char grade = ' ';
		
		System.out.print("당신의 점수를 입력하세요.(1~100)>");
		
		Scanner scanner = new Scanner(System.in);
		int score = scanner.nextInt();
		
		switch(score) {
		case 100: case 99: case 98: case 97: case 96:
		case 95: case 94: case 93: case 92: case 91: case 90:
		grade = 'A';
		break;
		case 89: case 88: case 87: case 86: case 85:
		case 84: case 83: case 82: case 81: case 80:
		grade = 'B';
		break;
		case 79: case 78: case 77: case 76: case 75:
		case 74: case 73: case 72: case 71: case 70:
		grade = 'C';
		break;
		default :
			grade = 'F';
			scanner.close();
		} // end of switch
		System.out.println("당신의 학점은 "+ grade +"입니다.");
	}
}
당신의 점수를 입력하세요.(1~100)>99
당신의 학점은 A입니다.

 

 

public class FlowEx10 {
	public static void main(String[] args) {
		int score = 0;
		char grade = ' ';
		
		System.out.println("당신의 점수를 입력하세요.(1~10)>");
		
		Scanner scanner = new Scanner(System.in);
		String tmp = scanner.nextLine();
		score = Integer.parseInt(tmp);
		
		switch(score/10) {
		case 10:
		case 9:
			grade = 'A';
			break;
		case 8:
			grade = 'B';
			break;
		case 7 :
			grade = 'C';
			break;
			default :
				grade = 'F';
		}// end of switch
		scanner.close();
		System.out.println("당신의 학점은 "+ grade +"입니다.");
	}//main의 끝
}
당신의 점수를 입력하세요.(1~10)>
5
당신의 학점은 F입니다.

 

 

 

public class FlowEx11 {
	public static void main(String[] args) {
		System.out.print("당신의 주민번호를 입력하세요. (011231-1111222)>");
		
		Scanner scanner = new Scanner(System.in);
		String regNo = scanner.nextLine();
		char gender = regNo.charAt(7);
		
		switch(gender) {
		case '1': case '3':
			switch(gender) {
			case '1':
				System.out.println("당신은 2000년 이전에 출생한 남자입니다.");
				break;
			case '3':
				System.out.println("당신은 2000년 이후에 출생한 남자입니다.");
			}
			break;
		case '2': case '4':
			switch(gender) {
			case '2':
				System.out.println("당신은 2000년 이전에출생한 여자입니다.");
				break;
			case '4':
				System.out.println("당신은 2000년 이후에 출생한 여자입니다.");
				break;
			}
			break;
			default:
				System.out.println("유효하지 않은 주민등록번호입니다.");

		}
		scanner.close();
	}//main의 끝
}
당신의 주민번호를 입력하세요. (011231-1111222)>354321-3205664
당신은 2000년 이후에 출생한 남자입니다.

 

 

public class FlowEx12 {
	public static void main(String[] args) {
		int i = 1;
		for (; i <= 5; i++) {
			System.out.println(i);// i의 값을 출력한다
		}

		for (; i <= 5;) {
			System.out.println(i);// i의 값을 출력한다
			i++;
		}

		for (; i <= 5; i++) {
			System.out.print(i);
		}

		System.out.println();
	}
}

 

 

 

public class FlowEx12 {
		public static void main(String[] args) {			
			for (int i = 1; i <= 5; i++) {
				System.out.println(i);
			}

			for (int i = 1; i <= 5; i++) {
				System.out.print(i);
			}

			System.out.println();
		}

	}
1
2
3
4
5
12345

 

 

 

public class FlowEx13 {
	public static void main(String[] args) {
		// 1부터 10까지의 합 구하기
		int sum = 0;	// 합계를 저장하기 위한 변수

		for (int i = 1; i <= 10; i++) {
			sum += i; //	sum = sum + i;
			System.out.printf("1부터 %d 까지의 합: %2d%n", i, sum);
		}
	}
}
1부터 1 까지의 합:  1
1부터 2 까지의 합:  3
1부터 3 까지의 합:  6
1부터 4 까지의 합: 10
1부터 5 까지의 합: 15
1부터 6 까지의 합: 21
1부터 7 까지의 합: 28
1부터 8 까지의 합: 36
1부터 9 까지의 합: 45
1부터 10 까지의 합: 55

 

 

 

public class FlowEx14 {
	public static void main(String[] args) {
		for (int i = 1, j = 10; i <= 10; i++, j--) { // 반복횟수 가급적 for문에서는 시작의 변수는 하나만
			System.out.printf("%d \t %d%n", i, j);
		}

		for (int i = 1; i <= 10; i++) {

		}

		for (int i = 0; i < 10; i++) {
			
		}
	}
}
1 	 10
2 	 9
3 	 8
4 	 7
5 	 6
6 	 5
7 	 4
8 	 3
9 	 2
10 	 1

 

 

public class FlowEx15 {
	public static void main(String[] args) {
//		 ctrl + F find/replace
		System.out.println("i \t 2*i \t 2*i-1 \t i*i \t 11-i \t i%3 \t i/3");
		System.out.println("--------------------------------------");
		
		for(int i=1;i<=10;i++)
			System.out.printf("%d \t %d \t %d \t %d \t %d \t %d \t %d%n ", i, 2*i, 2*i-1, i*i, 11-i, i%3, i/3);
	}
}
i 	 2*i 	 2*i-1 	 i*i 	 11-i 	 i%3 	 i/3
--------------------------------------
1 	 2 	 1 	 1 	 10 	 1 	 0
 2 	 4 	 3 	 4 	 9 	 2 	 0
 3 	 6 	 5 	 9 	 8 	 0 	 1
 4 	 8 	 7 	 16 	 7 	 1 	 1
 5 	 10 	 9 	 25 	 6 	 2 	 1
 6 	 12 	 11 	 36 	 5 	 0 	 2
 7 	 14 	 13 	 49 	 4 	 1 	 2
 8 	 16 	 15 	 64 	 3 	 2 	 2
 9 	 18 	 17 	 81 	 2 	 0 	 3
 10 	 20 	 19 	 100 	 1 	 1 	 3

 

 

public class FlowEx16 {
//반피라미드형
	public static void main(String[] args) {

		for (int i = 1; i <= 5; i++) {

			for (int j = 1; j <= i; j++) {
				
				System.out.printf("*");

			}
			System.out.println();
		}
	}

}
*
**
***
****
*****

 

 

public class FlowEx17 {
	public static void main(String[] args) {
		int num = 0;
		
		System.out.print("*을 출력할 라인의 수를 입력하세요.>");
		
		Scanner scanner = new Scanner(System.in);
		String tmp = scanner.nextLine();
		num = Integer.parseInt(tmp);
		
		for(int i =0; i<num;i++) {
			for(int j=0; j<=i;j++) {
				System.out.print("*");
			}
			System.out.println();
		}
		scanner.close();
	}
}
*을 출력할 라인의 수를 입력하세요.>10
*
**
***
****
*****
******
*******
********
*********
**********

 

 

public class FlowEx18 {
	public static void main(String[] args) {
		for(int i=2;i<=9;i++) {	//8
			for(int j=1;j<=9;j++) {	//9
				System.out.printf("%d x %d = %d%n", i, j, i*j); // 72
			}
		}
	}
}
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 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 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 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 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 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 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 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

 

 

 

public class FlowEx19 {
	public static void main(String[] args) {
		for(int i=1; i<=3;i++)
			for(int j=1;j<=3;j++)
				for(int k=1;k<=3;k++)
					System.out.println(""+i+j+k);
	}
}
111
112
113
121
122
123
131
132
133
211
212
213
221
222
223
231
232
233
311
312
313
321
322
323
331
332
333

 

 

 

public class FlowEx20 {
	public static void main(String[] args) {
		for(int i=1;i<=5;i++) {
			for(int j=1;j<=5;j++) {
				System.out.printf("[%d,%d]",i,j);
			}
			System.out.println();
		}
	}
}
[1,1][1,2][1,3][1,4][1,5]
[2,1][2,2][2,3][2,4][2,5]
[3,1][3,2][3,3][3,4][3,5]
[4,1][4,2][4,3][4,4][4,5]
[5,1][5,2][5,3][5,4][5,5]

 

 

 

public class FlowEx21 {
	public static void main(String[] args) {
		for(int i=1;i<=5;i++) {
			for(int j=1;j<=5;j++) {
				if(i==j) {
					System.out.printf("[%d,%d]",i,j);
				}else {
					System.out.printf("%5c",' ');
				}
			}
			System.out.println();
		}
	}
}
[1,1]                    
     [2,2]               
          [3,3]          
               [4,4]     
                    [5,5]

 

 

 

public class FlowEx22 {
	public static void main(String[] args) {
		int[] arr = {10,20,30,40,50};
		int sum = 0;
		
		for(int i=0;i<arr.length;i++)
			System.out.printf("%d ", arr[i]);
		System.out.println();
		
		for(int tmp : arr) {
			System.out.printf("%d ", tmp);
			sum +=tmp;
		}
		System.out.println();System.out.println("sum="+sum);
	}
}
10 20 30 40 50 
10 20 30 40 50 
sum=150

 

 

public class FlowEx23 {
	public static void main(String[] args) {
		int i = 5;

		while (i-- != 0) {
			System.out.println(i + " - I can do it.");
		}
	}	//main의 끝
}
4 - I can do it.
3 - I can do it.
2 - I can do it.
1 - I can do it.
0 - I can do it.

 

 

 

public class FlowEx24 {
	public static void main(String[] args) {
		int i = 11;

		System.out.println("카운트 다운을 시작합니다.");

		while (i-- != 0) {
			System.out.println(i);

			for (int j = 0; j < 2_000_000_000; j++) {	//슬립함수로 변형
				;
			}
		}
		System.out.println("GAME OVER");
	}
}
카운트 다운을 시작합니다.
10
9
8
7
6
5
4
3
2
1
0
GAME OVER

 

 

 

public class FlowEx25 {
	public static void main(String[] args) {
		int num = 0, sum = 0;
		System.out.print("숫자를 입력하세요. (예:12345)>");

		Scanner scanner = new Scanner(System.in);
		String tmp = scanner.nextLine();// 화면을 통해 입력받은 내용을 tmp에 저장;
		num = Integer.parseInt(tmp); // 입력받은 문자열(tmp)을 숫자로 변환

		while (num != 0) {
			// num을 10으로 나눈 나머지를 sum에 더함
			sum += num % 10; // sum = sum + num%10;
			System.out.printf("sum=%3d num%d%n", sum, num);

			num /= 10; // num = num / 10; num을 10으로 나눈값을 다시 num에 저장
		}

		System.out.println("각 자리수의 합:" + sum);
		scanner.close();
	}
}
숫자를 입력하세요. (예:12345)>123
sum=  3 num123
sum=  5 num12
sum=  6 num1
각 자리수의 합:6

 

 

public class FlowEx26 {
	public static void main(String[] args) {
		int sum = 0;
		int i	= 0;
		
		// i를 1씩 증가시켜서 sum에 계속 더해나간다.
		while((sum += ++i) <= 100) {
			System.out.printf("%d - %d%n", i, sum);
		}
	}//main의 끝
}
1 - 1
2 - 3
3 - 6
4 - 10
5 - 15
6 - 21
7 - 28
8 - 36
9 - 45
10 - 55
11 - 66
12 - 78
13 - 91

 

 

 

public class FlowEx27 {
	public static void main(String[] args) {
		int num;
		int sum = 0;
		boolean flag = true;	// while문의 조건식으로 사용될 변수
		Scanner scanner = new Scanner(System.in);
		
		System.out.println("합계를 구할 숫자를 입력하세요. (끝내려면 0을 입력)");
		
		while(flag) {	// flag의 값이 true이므로 조건식은 참이 된다.
			System.out.println(">>");
			
			String tmp = scanner.nextLine();
			num = Integer.parseInt(tmp);
			
			if(num!=0) {
				sum += num;	// num이 0이 아니면, sum에 더한다.
			}else {
				flag = false;	// num이 0이면, flag의 값을 flase로 변경.
			}
		}	// while문의 끝
		System.out.println("합계:"+sum);
		scanner.close();
	}
}
합계를 구할 숫자를 입력하세요. (끝내려면 0을 입력)
>>
55
>>
33
>>
78
>>
0
합계:166

 

 

 

public class FlowEx28 {
	public static void main(String[] args) {
		int input = 0, answer = 0;

		answer = (int) (Math.random() * 100) + 1; // 1~100사이의 임의의 수를 저장
		Scanner scanner = new Scanner(System.in);

		do {
			System.out.print("1과 100사이의 정수를 입력하세요.>");
			input = scanner.nextInt();

			if (input > answer) {
				System.out.println("더 작은 수로 다시 시도해보세요.");
			} else if (input < answer) {
				System.out.println("더 큰 수로 다시 시도해보세요.");
			}
		} while (input != answer);

		System.out.println("정답입니다.");
		scanner.close();
	}
}
1과 100사이의 정수를 입력하세요.>50
더 큰 수로 다시 시도해보세요.
1과 100사이의 정수를 입력하세요.>75
더 큰 수로 다시 시도해보세요.
1과 100사이의 정수를 입력하세요.>87
더 큰 수로 다시 시도해보세요.
1과 100사이의 정수를 입력하세요.>93
더 작은 수로 다시 시도해보세요.
1과 100사이의 정수를 입력하세요.>90
정답입니다.

 

 

 

public class FlowEx29 {
	public static void main(String[] args) {
		for (int i = 1; i <= 100; i++) {
			System.out.printf("i=%d ", i);

			int tmp = i;

			do {
				// tmp%10이 3의 배수인지 확인(0 제외)
				if (tmp % 10 % 3 == 0 && tmp % 10 != 0)
					System.out.print("짝");
				// tmp /=10은 tmp = tmp / 10과 동일

			} while ((tmp /= 10) != 0);

			System.out.println();
		}
	}
}
i=1 
i=2 
i=3 짝
i=4 
i=5 
i=6 짝
i=7 
i=8 
i=9 짝
i=10 
i=11 
i=12 
i=13 짝
i=14 
i=15 
i=16 짝
i=17 
i=18 
i=19 짝
i=20 
i=21 
i=22 
i=23 짝
i=24 
i=25 
i=26 짝
i=27 
i=28 
i=29 짝
i=30 짝
i=31 짝
i=32 짝
i=33 짝짝
i=34 짝
i=35 짝
i=36 짝짝
i=37 짝
i=38 짝
i=39 짝짝
i=40 
i=41 
i=42 
i=43 짝
i=44 
i=45 
i=46 짝
i=47 
i=48 
i=49 짝
i=50 
i=51 
i=52 
i=53 짝
i=54 
i=55 
i=56 짝
i=57 
i=58 
i=59 짝
i=60 짝
i=61 짝
i=62 짝
i=63 짝짝
i=64 짝
i=65 짝
i=66 짝짝
i=67 짝
i=68 짝
i=69 짝짝
i=70 
i=71 
i=72 
i=73 짝
i=74 
i=75 
i=76 짝
i=77 
i=78 
i=79 짝
i=80 
i=81 
i=82 
i=83 짝
i=84 
i=85 
i=86 짝
i=87 
i=88 
i=89 짝
i=90 짝
i=91 짝
i=92 짝
i=93 짝짝
i=94 짝
i=95 짝
i=96 짝짝
i=97 짝
i=98 짝
i=99 짝짝
i=100

 

 

 

public class FlowEx30 {
	public static void main(String[] args) {
		int sum = 0;
		int i = 0;
		
		while(true) {
			if(sum > 100)
				break;
			++i;
			sum +=i;
		}// end of while
		
		System.out.println("i=" + i);
		System.out.println("sum=" + sum);
	}
}
i=14
sum=105

 

 

 

public class FlowEx31 {
	public static void main(String[] args) {
		for (int i = 0; i <= 10; i++) {
			if (i % 3 == 0)
				continue;
			System.out.println(i);
		}
	}
}
1
2
4
5
7
8
10

 

 

 

public class FlowEx32 {
	public static void main(String[] args) {
		int menu = 0;
//		int num = 0;

		Scanner scanner = new Scanner(System.in);

		while (true) {
			System.out.println("(1) square");
			System.out.println("(2) square root");
			System.out.println("(3) log");
			System.out.println("원하는 메뉴(1~3)를 선택하세요. (종료:0)>");

			String tmp = scanner.nextLine();// 화면에서 입력받은 내용을 tmp에 저장
			menu = Integer.parseInt(tmp);

			if (menu == 0) {
				System.out.println("프로그램을 종료합니다.");
				break;
			} else if (!(1 <= menu && menu <= 3)) {
				System.out.println("메뉴를 잘못 선택하셨습니다.(종료는 0)");
				continue;
			}

			System.out.println("선택하신 메뉴는 " + menu + "번입니다.");
		}
		scanner.close();
	}
}
(1) square
(2) square root
(3) log
원하는 메뉴(1~3)를 선택하세요. (종료:0)>
1
선택하신 메뉴는 1번입니다.
(1) square
(2) square root
(3) log
원하는 메뉴(1~3)를 선택하세요. (종료:0)>
0
프로그램을 종료합니다.

 

 

 

public class FlowEx33 {
	public static void main(String[] args) {
		// for문에 Loop1이라는 이름을 붙였다.
//		Loop1:
			for (int i = 2; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				if (j == 5)
//					break Loop1;
//				break;
//				continue Loop1;
				continue;
				System.out.println(i + "*" + j + "=" + i * j);
			} // end of for i
			System.out.println();
		} // end of Loop1
	}
}
2*1=2
2*2=4
2*3=6
2*4=8
2*6=12
2*7=14
2*8=16
2*9=18

3*1=3
3*2=6
3*3=9
3*4=12
3*6=18
3*7=21
3*8=24
3*9=27

4*1=4
4*2=8
4*3=12
4*4=16
4*6=24
4*7=28
4*8=32
4*9=36

5*1=5
5*2=10
5*3=15
5*4=20
5*6=30
5*7=35
5*8=40
5*9=45

6*1=6
6*2=12
6*3=18
6*4=24
6*6=36
6*7=42
6*8=48
6*9=54

7*1=7
7*2=14
7*3=21
7*4=28
7*6=42
7*7=49
7*8=56
7*9=63

8*1=8
8*2=16
8*3=24
8*4=32
8*6=48
8*7=56
8*8=64
8*9=72

9*1=9
9*2=18
9*3=27
9*4=36
9*6=54
9*7=63
9*8=72
9*9=81

 

 

 

import java.util.*;

public class FlowEx34 {
	public static void main(String[] args) {
		int menu = 0, num = 0;
		
		Scanner scanner = new Scanner(System.in);
		
		outer:
			while(true) {
				System.out.println("(1) square");
				System.out.println("(2) square root");
				System.out.println("(3) log");
				System.out.println("원하는 메뉴(1~3)를 선택하세요.(종료0)>");
				
				String tmp = scanner.nextLine();	// 화면에서 입력받은 내용을 tmp에 저장
				menu = Integer.parseInt(tmp);		// 입력받은 문자열(tmp)를 숫자로 변환
				
				if(menu==0) {
					System.out.println("프로그램을 종료합니다.");
					break;
				}else if (!(1<= menu && menu <=3)) {
					System.out.println("메뉴를 잘못 선택하셨습니다.(종료는0)");
					continue;
				}
				
				for(;;) {
					System.out.print("계산할 값을 입력하세요.(계산 종료:0, 전체 종료:99)>");
					tmp = scanner.nextLine();		// 화면에서 입력받은 내용을 tmp에 저장
					num = Integer.parseInt(tmp);	// 입력받은 문자열(tmp)를 숫자로 변환
					
					if(num==0)
						break;
					
					if(num==99)
						break outer;
					
					switch(menu) {
					case 1:
						System.out.println("result="+ num*num);
						break;
					case 2:
						System.out.println("result="+ Math.sqrt(num));
						break;
					case 3:
						System.out.println("result="+ Math.log(num));
						break;
					}
				} // for(;;)
			} // while의 끝
	}// main의 끝

}
(1) square
(2) square root
(3) log
원하는 메뉴(1~3)를 선택하세요.(종료0)>
1
계산할 값을 입력하세요.(계산 종료:0, 전체 종료:99)>25
result=625
계산할 값을 입력하세요.(계산 종료:0, 전체 종료:99)>0
(1) square
(2) square root
(3) log
원하는 메뉴(1~3)를 선택하세요.(종료0)>
2
계산할 값을 입력하세요.(계산 종료:0, 전체 종료:99)>25
result=5.0
계산할 값을 입력하세요.(계산 종료:0, 전체 종료:99)>0
(1) square
(2) square root
(3) log
원하는 메뉴(1~3)를 선택하세요.(종료0)>
3
계산할 값을 입력하세요.(계산 종료:0, 전체 종료:99)>100
result=4.605170185988092
계산할 값을 입력하세요.(계산 종료:0, 전체 종료:99)>99

 

 

+ Recent posts