//------ CH02. ForTest- for 문 기본 ------
/*
	for문
	     -형식:
	       	       
	       for(1;2;3){
	       	//1.반복변수(선언,초기화가능)
	       	 * 	 -> 타입과 identifier -> 변수의 구조와크기
	       	//2.반복변수의 조건검사(논리형데이타)
	       	//3.반복변수증,감(++,--)
	       }
	       
	       ex>
	       for(int i=0;i<10;i++){
	       	 stmt1;
	       }
	       ex>무한루프
	       for(;;){
	       	
	       }
	       	* -> 무한루프도 OCJP출제
	
	*/
public class ForTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int i, j;
		//****구구단*****
		System.out.println("\n===============구구단 출력==============");
		for (i=1; i<10; i++){
			for (j=2;j<10; j++){
				System.out.print(j+" X "+i+" = "+i*j+"\t");
			}
			System.out.println();
		}
		System.out.println("\n===============modular for test ==============");
		
		//*****modular 4*******
		System.out.print("1~10 중 4로 나누어 떨어지는 수는 ");
		for (i=1; i<=10; i++){
			if (i%4 == 0){
				System.out.print(i+", ");
			}
		}
		System.out.println("이다.");
		
		
		//******1~10 중 홀수 합
		System.out.println("\n==============sum of odd while 1 to 10===============");

		int sum=0;
		
		for (i=1; i<=10; i++){
			if(i%2 ==1){
				sum+=i;
				/*
				 * 연산 후 대입 연산자
				 * 
				 * a+=b; == a=a+b;
				 * a-=b; == a=a-b;
				 * a*=b; == a=a*b;
				 * a/=b; == a=a/b;
				 * 
				 */
			}
		}
		System.out.println("1~10까지 홀수의 합은 "+sum+"이다.");

		//******알파벳 소문자 출력
		System.out.println("\n==============small alphabet print===============");
		char alphabet = 'a';
		int count=0;
		for (alphabet = 'a'; alphabet<= 'z' ; alphabet++){
			System.out.print(alphabet+" ");
			count ++;
			
			if (count%4 == 0){
				System.out.println();
			}
		}
		
		//감소
		count =0;
		System.out.println("\n==============for 감소===============");
		for (alphabet = 'z'; alphabet>= 'a' ; alphabet--){
			System.out.print(alphabet+" ");
			count ++;
			
			if (count%4 == 0){
				System.out.println();
			}
		}
		
		//2씩 증가
		System.out.println("\n==============2씩 증가===============");
		for (i =0; i<100; i+=2){
			System.out.print(i+" ");
		}
		
		//2씩 감소
		System.out.println("\n==============2씩 감소===============");
		for (i=100; i>0; i-=2){
			System.out.print(i+" ");
		}
		
		
	}//end main

}
 
===============구구단 출력==============
2 X 1 = 2	3 X 1 = 3	4 X 1 = 4	5 X 1 = 5	6 X 1 = 6	7 X 1 = 7	8 X 1 = 8	9 X 1 = 9	
2 X 2 = 4	3 X 2 = 6	4 X 2 = 8	5 X 2 = 10	6 X 2 = 12	7 X 2 = 14	8 X 2 = 16	9 X 2 = 18	
2 X 3 = 6	3 X 3 = 9	4 X 3 = 12	5 X 3 = 15	6 X 3 = 18	7 X 3 = 21	8 X 3 = 24	9 X 3 = 27	
2 X 4 = 8	3 X 4 = 12	4 X 4 = 16	5 X 4 = 20	6 X 4 = 24	7 X 4 = 28	8 X 4 = 32	9 X 4 = 36	
2 X 5 = 10	3 X 5 = 15	4 X 5 = 20	5 X 5 = 25	6 X 5 = 30	7 X 5 = 35	8 X 5 = 40	9 X 5 = 45	
2 X 6 = 12	3 X 6 = 18	4 X 6 = 24	5 X 6 = 30	6 X 6 = 36	7 X 6 = 42	8 X 6 = 48	9 X 6 = 54	
2 X 7 = 14	3 X 7 = 21	4 X 7 = 28	5 X 7 = 35	6 X 7 = 42	7 X 7 = 49	8 X 7 = 56	9 X 7 = 63	
2 X 8 = 16	3 X 8 = 24	4 X 8 = 32	5 X 8 = 40	6 X 8 = 48	7 X 8 = 56	8 X 8 = 64	9 X 8 = 72	
2 X 9 = 18	3 X 9 = 27	4 X 9 = 36	5 X 9 = 45	6 X 9 = 54	7 X 9 = 63	8 X 9 = 72	9 X 9 = 81	

===============modular for test ==============
1~10 중 4로 나누어 떨어지는 수는 4, 8, 이다.

==============sum of odd while 1 to 10===============
1~10까지 홀수의 합은 25이다.

==============small alphabet print===============
a b c d 
e f g h 
i j k l 
m n o p 
q r s t 
u v w x 
y z 
==============for 감소===============
z y x w 
v u t s 
r q p o 
n m l k 
j i h g 
f e d c 
b a 
==============2씩 증가===============
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 
==============2씩 감소===============
100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 
//------ CH02. ForGuGuDan- for문을 이용한 구구단 ------
public class ForGuGuDan {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int i, j;
		//****구구단*****
		System.out.println("\n===============구구단 출력==============");
		for (i=1; i<10; i++){
			for (j=2;j<10; j++){
				System.out.print(j+" X "+i+" = "+i*j+"\t");
			}
			System.out.println();
		}
	}

}
 
//------ CH02. ForNested- for문으로 별 찍기 ------
		/*
		 ☆★★★★
		 ★☆★★★
		 ★★☆★★
		 ★★★☆★
		 ★★★★☆ 
		 */
public class ForNested {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int i, j;

		
		System.out.println("*****별 찍기 1*****\n");
		for (i=0; i<5; i++){
			for (j=0; j<5; j++){
				if (i == j){
					System.out.print("☆");
				}
				else{
				System.out.print("★");
				}
			}
			System.out.println();
		}
		
		
		System.out.println("*****별 찍기 2*****\n");
		/*
		 ★☆☆☆☆
		 ★★☆☆☆
		 ★★★☆☆
		 ★★★★☆
		 ★★★★★ 
		 */
		for (i=0; i<5; i++){
			for (j=0; j<=i; j++){
				System.out.print("★");
			}
			for (int k=4; k>i; k--){
				System.out.print("☆");
			}
			System.out.println("");
		}
		

		System.out.println("*****별 찍기 3*****\n");
		/*
		 ☆☆☆☆★ 
		 ☆☆☆★★ 
		 ☆☆★★★ 
		 ☆★★★★ 
		 ★★★★★ 
		 */
		for (i=0; i<5; i++){
			for (j=4; j>i; j--){
				System.out.print("☆");
			}
			for (int k=0; k<=i; k++){
				System.out.print("★");
			}
			System.out.println();
		}
		

		System.out.println("*****별 찍기 4*****\n");
		/*
		 ★★★★★
		 ★★★★
		 ★★★
		 ★★
		 ★ 
		 */		
		for (i=0; i<5; i++){
			for (j=5; j>i; j--){
				System.out.print("★");
			}
			System.out.println();
		}
		
		
	}//end main

}

 
//------ CH02. Switch,While - 정수 홀짝 구분, 알파벳 출력 ------
import java.util.Scanner;

/*
 * 1.정수를 입력받아서 짝수인지 홀수인지 출력(switch)

2.알파벳 대문자출력(4개찍고 개행)(while)
   ex> ABCD
       EFGH
       IJKL
       ...
	
		 

 */
public class HomeWork_3_0220 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

//정수를 입력받아서 짝수인지 홀수인지 출력(switch)	
		Scanner sc = new Scanner(System.in);
		
		int num; 
		int nextLine =0;
		int alphabet =65;
		char alpha ='A'; //int 65
		
		System.out.println("숫자하나 입력");
		num = sc.nextInt();
		
		num = num%2;
		
		switch (num){
		case 1:
			System.out.println("홀수");
			break;
			
		case 0:
			System.out.println("짝수");
			break;
		
		}
		
//알파벳 대문자출력(4개찍고 개행)(while)
		num =0;
		
		while (num < 26){
			System.out.print(alpha);
			nextLine++;
			while (nextLine > 4){
				System.out.println("");
				nextLine =0;
			}
			num++;
			alpha++;	
		}

	}

}

 
//------ CH02. SwitchScoreTest - switch 문으로 점수 구분하기 ------
import java.util.Scanner;


public class SwitchScoreTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		
		Scanner sc = new Scanner(System.in);
		
		int kor,eng,math;
		kor=71;
		eng=52;
		math=91;

		System.out.println("국어,영어,수학 점수 입력");
		kor = sc.nextInt();
		eng = sc.nextInt();
		math = sc.nextInt();
		
		int total = kor+eng+math;
		float everage = (float)total/3; 
		char hakjum;
		
		everage = everage*100;
		int trans = (int)everage;
		everage = (float)trans/100;

		int switch_triger = (int)everage/10;
		
		/**점수 타당성 검사 **/

		if (kor<0 || kor>100){
			System.out.println("ERROR, SCORE is Between 0 to 100");
			return; //해당 경우에 하위 문장을 실행하지 않고 return
		}
		if (eng<0 || eng>100){
			System.out.println("ERROR, SCORE is Between 0 to 100");
			return; //해당 경우에 하위 문장을 실행하지 않고 return
		}
		
		if (math<0 || math>100){
			System.out.println("ERROR, SCORE is Between 0 to 100");
			return; //해당 경우에 하위 문장을 실행하지 않고 return
		}
		
		System.out.println("************************");
		System.out.println("국어: "+kor);
		System.out.println("영어: "+eng);
		System.out.println("수어: "+math);
		System.out.println("총점: "+total);
		System.out.println("평균: "+everage);
		
		switch (switch_triger){
		case 10:
			hakjum='S';
			break;
		case 9:
			hakjum = 'A';
			break;
			
		case 8:
			hakjum = 'B';
			break;
		case 7:
			hakjum = 'C';
			break;
		case 6:
			hakjum ='D';
			break;
			
		default:
			hakjum ='F';		
		}

		System.out.println("평점: "+hakjum);
		System.out.println("************************");
	}

}
 
//------ CH02. whileGuGuDan- while문을 이용한 구구단 ------
public class WhileGuGuDan {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int i=1, j=2;
		
		while (i<10){
			while (j<10){
				System.out.print(j+" X "+i+" = "+i*j+"\t");
				j++;
			}
			j =2;
			System.out.println();
			i++;
		}
	}//end main

}//and class