스마트 인재개발원/자바페스티벌

2021-05-07 자바페스티벌 끝(스마트인재개발원)

JavaFestival 알고리즘문제(배포).pptx
1.11MB
JavaFestival 알고리즘문제예시(1차배포).pptx
0.12MB
JavaFestival 알고리즘문제예시(2차배포) (1).pptx
0.69MB
JavaFestival 알고리즘문제예시(3차배포).pptx
0.12MB

package Chapter05;

public class 피보나치수혈 {

	   public static void main(String[] args) {
		   
	        int input = 8;
	 
	        for (int i=1; i<= input; i++) {
	            System.out.print(fibo(i) + " ");
	        }
	 
	    }
	 
	    public static int fibo(int i) {
	        if (i <= 1)
	            return i;
	        else
	            return fibo(i-2) + fibo(i-1);
	    }
	    
}​
package Chapter05;

import java.util.Scanner;

public class 행개수입력받아별출력 {
    public static void main(String[] args) {
    	 
        Scanner sc = new Scanner(System.in);
        System.out.print("행 개수 : ");
        int num = sc.nextInt();
 
        for (int i = 0; i < num; i++) {
 
            for (int j = num; j > i; j--) {
 
                System.out.print("*");
            }
 
            System.out.println();
        }
 
    }
 
}
package Chapter05;

import java.util.Scanner;

public class 최대공약수최소공배수 {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        System.out.print("숫자1입력>>");
        int num1 = sc.nextInt();
        System.out.print("숫자2입력>>");
        int num2 = sc.nextInt();
        int x = 0;
        int i = 0;
 
        for (i = 1; i <= num1; ++i) {
            if (num1 % i == 0 && num2 % i == 0) {
                x = i;
            }
        }
        
        System.out.println("최대공약수 : " + x);
        int num3 = num1 * num2 / x;
        System.out.println("최소공배수 : " + num3);
 
    }
 
}
 
package Chapter05;

import java.util.Scanner;

public class 일할시간 {
    
    public static void main(String[] args) {
        
        Scanner sc=new Scanner (System.in);
        int work;
        int money=5000;
        float s=1.5f;
 
        System.out.println("근무한 시간을 입력하세요 : ");
        work=sc.nextInt();
 
        if (work>8) { 
            System.out.println(8*money+(work-8)*5000*s+"원 입니다.");
            
        }else {
            System.out.println(work*money+"원 입니다.");
        }
        
    }
    
}
package Chapter05;

public class 일차원의점가장짧은점 {

	 public static void main(String[] args) {
		
	
    int[] point = { 92, 32, 52, 9, 81, 2, 68 };
    int min = Math.abs(point[0] - point[1]);

    String result = null;

    for (int i = 0; i < point.length; i++) {

        for (int j = 1; j < point.length; j++) {

            if (i != j) {

                if (min > Math.abs(point[i] - point[j])) {
                    min = Math.abs(point[i] - point[j]);

					 result = "[" + point[i] + ", " + point[j] + "]"; 
                }

            }

        }

    }

    System.out.println(result);
}

}


package Chapter05;

import java.util.Scanner;

public class 실습문제03_동전교환문제 {
	public static void main(String[] args) {
		
		//금액 입력받기 
		Scanner sc = new Scanner(System.in);
		System.out.print("금액을 입력하시오>>");
		int amount = sc.nextInt();
		
		int o_man_won = amount/50000;
		int man_won = amount%50000/10000;
		int chun_won = amount%50000%10000/1000;
		int back_won = amount%50000%10000%1000/100;
		int o_sip_won = amount%50000%10000%1000%100/50;
		int sip_won = amount%50000%10000%1000%100%50/10;
		int il_won = amount%50000%10000%1000%100%50%10;
		
		
		System.out.println("오만원권 " + o_man_won + "매");
		System.out.println("만원권 " + man_won + "매");
		System.out.println("천원권 " + chun_won + "매");
		System.out.println("백원 " + back_won + "매");
		System.out.println("오십원 " + o_sip_won + "매");
		System.out.println("십원 " + sip_won + "매");
		System.out.println("일원 " + il_won + "매");
		
		
	}
}
package Chapter05;

public class 성적별학생출력 {

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

        String score = "A,A,B,C,D,A,C,D,D,D,F";
        
        String[] cut = score.split(",");
 
        int A=0, B=0, C=0, D=0, F=0;
 
        for (int i=0; i<cut.length; i++) {
 
            if (cut[i].equals("A")) {
                A++;
            } else if (cut[i].equals("B")) {
                B++;
            } else if (cut[i].equals("C")) {
                C++;
            } else if (cut[i].equals("D")) {
                D++;
            } else {
                F++;
            }
         
        }
 
        System.out.println("A : " + A + "명\n"
            + "B : " + B + "명\n"
            + "C : " + C + "명\n"
            + "D : " + D + "명\n"
            + "F : " + F + "명\n");
            
    }
}
package Chapter05;

import java.util.Scanner;

public class 몸무게 {

	 public static void main(String[] args) {
	        
	        System.out.println("Hello");
	        
	        Scanner sc=new Scanner (System.in);
	        int week=0;
	        int sum=0;
	        
	        System.out.print("현재몸무게 : ");
	        int num1=sc.nextInt();
	        System.out.print("목표몸무게 : ");
	        int num2=sc.nextInt();
	 
	 
	        while (num1>num2) {
	            week++;
	            System.out.print(week+"주차감량몸무게: ");
	            sum=sc.nextInt();
	            num1-=sum;
	            
	        }
	        
	        System.out.println(num1+"KG 달성!! 축하합니다!!");
	    
	    }
	    
	}
package Chapter05;

public class 다음과같일차원점주어졌을때 {

public static void main(String[] args) {
	

int[] point = { 56, 13, 1, 8, 87, 17, 23 };

int min = Math.abs(point[0] - point[1]);

String result = null;

for (int i = 0; i < point.length; i++) {

    for (int j = 1; j < point.length; j++) {

        if (i != j) {

            if (min > Math.abs(point[i] - point[j])) {
                min = Math.abs(point[i] - point[j]);

                result = "[" + point[i] + ", " + point[j] + "]";
            }

        }

    }

}

System.out.println(result);
}
}