본문 바로가기
Coding Test/CodeUp

CodeUp_Java 기초 100제 - [기초-종합] 78~86

by SeleniumBindingProtein 2022. 2. 14.
728x90
반응형

78 : 짝수 합 구하기

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
        sc.close();
        
        int b = 0;
        for(int i=0;i<b;i++){
        	if(i%2==0){
            	b += i;
            }
        }
        System.out.println(a);
    }
}

79 : 원하는 문자가 입력될 때까지 반복 출력하기

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		char ch;
        while(true){
        	ch = sc.next().charAt(0);
            if(ch == 'q'){
            	break;
            }
        	System.out.println(a);
        }
        
        sc.close();
    }
}

80 : 언제까지 더해야 할까?

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
        int b = 0, i = 0;
        
        while(b<a){
        	i++;
            b += i;
        }
        System.out.println(i);
        sc.close();
    }
}

81 : 주사위를 2개 던지면?

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
        
        if(n>0 && n<=10){
        	int m = sc.nextInt();
            sc.close();
            
            if(m>0 && m<=10){
        		for(int i =1;i<=n;i++){
            		for(int j =1;j<=m;j++){
                		System.out.print(i+" "+j);
                    	System.out.println();
                	}
            	}
        	 } else{
         	 }
        } else{
        }
    }
}

82 : 16진수 구구단?

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int a = sc.nextInt(16
        sc.close();
        
        for(int i=1;i<16++){
        	System.out.println("%X*%X=%X\n", a,i,a*i);
        }
        
    }
}

83 : 3 6 9 게임의 왕이 되자!

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
        sc.close();
        
        for(int i=1;i<=a;i++){
        	if(i%3==0){
            	System.out.print("X ");
            }
       		} else {
        		System.out.println(i + " ");
        	}
        }
    }
}

84 : 빛 섞어 색 만들기

//자바코드
import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();
        
        BufferedWriter bf = new BufferedWriter(new OutputStreamWriter(System.out));
        
        for(int i=0;i<a;i++){
        	for(int j=0;j<b;j++){
        		for(int k=0;k<c;k++){
        			String st = i+ " " + j +" " +k;
                    bf.write(st + "\n");
                }
            }
        }
        bf.write(Integer.toString(a*b*c);
        bf.close();
    }
}

 


85 : 소리 파일 저장용량 계산하기

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        sc.close();
        
        double cal = Math.pow(2, 23);
        double total = a*b*c*d;
        double result = total/cal;
        System.out.println("%.1f MB", result));
    }
}

86 : 그림 파일 저장용량 계산하기 

//자바코드
import java.util.Scanner;

public class Main{
	public static void main (String[] args){
    	Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();
        
        double cal = Math.pow(2, 23);
        double total = a*b*c;
        double result = total/cal;
        System.out.println("%.2f MB", result));
    }
}
728x90
반응형

댓글