알고리즘 공부/CodeUp기초100제

[Code up/코드업]C언어 기초 문제100제 자바로 풀기 java 1061~1080

콩이아부지이 2021. 7. 26. 16:42
728x90

1061 : [기초-비트단위논리연산] 비트단위로 OR 하여 출력하기

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();
		System.out.println(a | b);
	}
}

 


1062 : [기초-비트단위논리연산] 비트단위로 XOR 하여 출력하기

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();
		System.out.println(a ^ b);
	}
}

}


1063 : [기초-삼항연산] 두 정수 입력받아 큰 수 출력하기

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();
		System.out.println(a > b ? a : b);
	}
}

1064 : [기초-삼항연산] 정수 3개 입력받아 가장 작은 수 출력하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int min;
		int a =sc.nextInt();
		int b =sc.nextInt();
		int c =sc.nextInt();
		min = a < b ? a : b ; // a,b 작은 값 비교해서 min에 대입
		System.out.println(min < c ? min : c); //min,c 비교
	}
}

 


1065 : [기초-조건/선택실행구조] 정수 3개 입력받아 짝수만 출력하기

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();
		if (a % 2 == 0 )System.out.println(a);
		if (b % 2 == 0 )System.out.println(b);
		if (c % 2 == 0 )System.out.println(c);
	}
}

 


1066 : [기초-조건/선택실행구조] 정수 3개 입력받아 짝/홀 출력하기

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();
		if (a % 2 == 0 )System.out.println("even");
		else System.out.println("odd");
		if (b % 2 == 0 )System.out.println("even");
		else System.out.println("odd");
		if (c % 2 == 0 )System.out.println("even");
		else System.out.println("odd");
	}
}

1067 : [기초-조건/선택실행구조] 정수 1개 입력받아 분석하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a =sc.nextInt();
		if (a < 0)System.out.println("minus");
		else System.out.println("plus");
		if (a % 2 == 0)System.out.println("even");
		else System.out.println("odd");
	}
}

1068 : [기초-조건/선택실행구조] 정수 1개 입력받아 평가 출력하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a =sc.nextInt();
		if (a >= 90 && 100 >= a)System.out.println("A");
		else if (a >= 70 && 90 > a)System.out.println("B");
		else if (a >= 40 && 70 > a)System.out.println("C");
		else if (a >= 0 && 40 > a)System.out.println("D");
	}
}

1069 : [기초-조건/선택실행구조] 평가 입력받아 다르게 출력하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		switch(a.charAt(0)) {
		case 'A' :System.out.println("best!!!");
		break;
		case 'B' :System.out.println("good!!");
		break;
		case 'C' :System.out.println("run!");
		break;
		case 'D' :System.out.println("slowly~");
		break;
		default : System.out.println("what?");
		}

	}
}

1070 : [기초-조건/선택실행구조] 월 입력받아 계절 출력하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		
		switch(a) {
		case 1 :
		case 2 :System.out.println("winter");
		break;
		case 3 :
		case 4 :
		case 5 :System.out.println("spring");
		break;
		case 6 :
		case 7 :
		case 8 :System.out.println("summer");
		break;
		case 9 :
		case 10 :
		case 11 :System.out.println("fall");
		break;
		case 12 :System.out.println("winter"); //12월 입력이안되서 출력문추가
		}
	}
}

1071 : [기초-반복실행구조] 0 입력될 때까지 무한 출력하기1

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			
			int a = sc.nextInt();
			if (a == 0)break;
			System.out.println(a);
		}
	}
}

1072 : [기초-반복실행구조] 정수 입력받아 계속 출력하기

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 = new int[a]; //배열 선언
		for (int i = 0; i < b.length; i++) {
			b[i] =sc.nextInt();
			System.out.println(b[i]);
		}
	}
}

1073 : [기초-반복실행구조] 0 입력될 때까지 무한 출력하기2

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			
			int a = sc.nextInt();
			if (a == 0)break;
			System.out.println(a);
		}
	}
}

1074 : [기초-반복실행구조] 정수 1개 입력받아 카운트다운 출력하기1

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt(); //정수 입력 5
		
		for (int i = a; i >= 1; i--) { // 5가 1보다 작거나 같을때 까지 출력
			System.out.println(i);
		}
	}
}

1075 : [기초-반복실행구조] 정수 1개 입력받아 카운트다운 출력하기2

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt(); //정수 입력 5
		
		for (int i = a - 1; i >= 0; i--) { // 4가 0보다 작거나 같을때 까지 출력
			System.out.println(i);
		}
	}
}

1076 : [기초-반복실행구조] 문자 1개 입력받아 알파벳 출력하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String a = sc.next();
		char[] b = a.toCharArray(); // a == 97 98 99 100 101 f == 102
		int d = a.charAt(0) - 97; // d값 5
		for (int i = d; i >= 0; i--) { // 6번 실행
			int c = a.charAt(0) - i ; //i가 1씩감소 하면서 대입 첫 값 102 - 5 = 97
			System.out.print((char)c + " ");
		}
	}
}

1077 : [기초-반복실행구조] 정수 1개 입력받아 그 수까지 출력하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		for (int i = 0; i <= a; i++) {
			System.out.println(i);
		}
	}
}

1078 : [기초-종합] 짝수 합 구하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum = 0;
		int a = sc.nextInt();
		for (int i = 1; i <= a; i++) {
			if(i % 2 == 0) {
				sum += i;
			}
		}
		System.out.println(sum);
	}
}

1079 : [기초-종합] 원하는 문자가 입력될 때까지 반복 출력하기

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine(); //입력
		char[] b = a.toCharArray(); // char 배열로 변환
		for (int i = 0; i < b.length; i++) {
			if(i % 2 == 0 )// 공백들어있는 인덱스 제거
			System.out.println(b[i]); //출력
			if(b[i] == 'q')break; // 반복문 종료조건
		}
	}
}

1080 : [기초-종합] 언제까지 더해야 할까?

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i,sum = 0;
		int a = sc.nextInt();
		for (i = 0; i < a; i++) {
			if(sum >= a)break;
			sum += i;
		}
		System.out.println(i-1);
	}
}
728x90