Study/알고리즘

JAVA 백준 알고리즘 단계별로 풀어보기 - 2

토기발 2022. 5. 23. 23:03

2739번

N을 입력받은 뒤, 구구단 N단을 출력하는 프로그램을 작성하시오. 출력 형식에 맞춰서 출력하면 된다.

 

public class googoo {
	public static void main(String[] args) {
		int N;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		
		for(int i = 1; i <=9; i++ ) {
			System.out.println(N+" " + "*"+" " + i +" "+ "="+" " + N * i );
			
		}
		
	}
}

 

 

10950번

두 정수 A와 B를 입력받은 다음, A+B를 출력하는 프로그램을 작성하시오.

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

 

 

8393번

n이 주어졌을 때, 1부터 n까지 합을 구하는 프로그램을 작성하시오.

public class Main {

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