ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 배열문| 성적관리 1, 2
    과거⚰️ 2020. 10. 7. 14:33
    package day015;
    
    import java.util.Scanner;
    
    public class Day01504배열응용1 {
    	public static void main(String[] args) {
    		//1. 다음 리스트의 값을 입력하면 번호를 출력
    		// 51  =>   2
    		Scanner sc = new Scanner(System.in);
    		
    		int[] a = {10, 49, 51, 36, 17};
    		System.out.println("enter");
    		int z = sc.nextInt();
    		
    		for(int i =0; i<5; i++) {
    				if(a[i]==z) {
    				System.out.print(i);	
    				}
    		}
    		
    		System.out.println();
    		//2. 배열 a의 값 중에 홀수만 배열 b에 저장(위치 종일)
    		// b = {0, 49, 51, 0, 17}
    		int[] b = {0, 0, 0, 0, 0};
    		for(int i=0; i<5; i++) {
    			if(a[i]%2!=0) {
    				b[i]=a[i];
    			}
    			System.out.print(b[i]+" ");
    		}
    		
    		
    		
    		System.out.println();
    		
    		//3. 배열 a의 값 중에 홀수만 배열 c에 저장(위치 앞에서 부터)
    		// c = {49, 51, 17, 0, 0}
    		int[] c = new int[5];
    		int x = 0;
    		for(int i=0; i<5; i++) {
    			if(a[i]%2!=0) {
    				c[x] = a[i];
    				x++;
    			}
    		}
    		for(int i=0; i<5; i++) {
    			System.out.print(c[i]+" ");
    		}
    		//학번과 점수가 한쌍이다.
    		// 1001:20 1002:45 1003:54
    		
    		
    		//4. 학번을 입력하면 점수 출력
    		//1002 => 45
    		
    		int[] info = {1001, 20, 1002, 45, 1004, 54};
    		System.out.println("학번");
    		int hak = sc.nextInt();
    		for(int i = 0; i<5; i++) {
    			if(info[i]==hak) {
    				System.out.println(info[i+1]);
    			}
    		}
    		//5. 점수를 입력하면 학번출력
    		//45 => 1002
    		System.out.println("점수");
    		int score = sc.nextInt();
    		for(int i = 0; i<5; i++) {
    			if(info[i]==score) {
    				System.out.println(info[i-1]);
    			}
    		}
    	}
    
    }
    
    
    package day015;
    
    import java.util.Scanner;
    
    public class Day015학생성적관리프로그램3 {
    	public static void main(String[] args) {
    		
    		int[] hakbuns = {100, 1002, 1003, 1004, 1005};
    		int[] scores = { 87, 11, 45, 98, 23};
    		
    			//1. 학번을 입력받아 성적출력
    			// 없는 학번 예외
    			// 예
    			// 학번 입력 : 1002   성적 : 11점
    			// 학번 입력 : 1000  해당학번은 존재하지 않습니다.
    		Scanner sc = new Scanner(System.in);
    		System.out.println("학번");
    		int num = sc.nextInt();
    		int x = -1;
    		for(int i =0; i<5; i++) {
    			if(hakbuns[i] == num) {
    				x = i;
    				System.out.println("score = " + scores[x]);
    			}
    			else if(x== -1) {
    				System.out.println("nothing");
    			}
    		
    		}
    		
    //		for(int i=0; i<5; i++) {
    //			if(hakbuns[i]==num) {
    //				System.out.println(scores[i]);
    //				
    //			}else if(hakbuns[i]!=num){
    //				System.out.println("학번이 존재하지 않습니다.");
    //			}
    //		}
    		
    	}
    
    }
    
    package day015;
    
    public class Day015학생성적관리프로그램4 {
    	public static void main(String[] args) {
    		int[] hakbuns = {100, 1002, 1003, 1004, 1005};
    		int[] scores = { 87, 11, 45, 98, 23};
    		
    		/* 1. 1등 학생의 학번과 성적출력
    		 * 1004학번(98점)
    		 */
    		int y=0;
    		int x = 0;
    		for(int i=0; i<5; i++) {
    			if(x<scores[i]) {
    				x = scores[i];
    				y++;
    			}
    		}
    		System.out.println(hakbuns[y]+", "+x);
    	}
    
    }
    
Designed by Tistory.