오늘은 백준 이라는 곳에서 For문 예제 풀기를 해보자
문제 출처는 아래의 링크를 참고하였습니다.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 1; i < 10; i++) {
System.out.println(x + " * " + i + " = " + x*i);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 0; i < x; i++) {
int y = sc.nextInt();
int z = sc.nextInt();
System.out.println(y + z);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int sum = 0;
for (int i = 1; i <= x; i++) {
sum += i;
}
System.out.println(sum);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 1; i <= x; i++) {
System.out.println(i);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 0; i < x; i++) {
System.out.println(x - i);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 0; i < x; i++) {
int y = sc.nextInt();
int z = sc.nextInt();
System.out.println("Case #" + (i + 1) + ": " + (y + z));
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 0; i < x; i++) {
int y = sc.nextInt();
int z = sc.nextInt();
System.out.println("Case #" + (i + 1) + ": " + y + " + " + z + " = " + (y + z));
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 1; i < x + 1; i++) {
for (int j = 0; j < i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for (int i = 0; i < x ; i++) {
for (int j = 0; j < x - i - 1; j++) {
System.out.print(" ");
}
for (int z = 0; z < i+1; z++) {
System.out.print("*");
}
System.out.println();
}
}
}