num를 입력받아서 num의 약수 출력 // Scanner 클래스를 사용하기 위한 import 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(); System.out.print(num+"의 약수> "); for(int i=1; i
1부터 10까지 짝수의 합과 홀수의 합 출력 public class 홀짝누적더하기 { public static void main(String[] args) { // 짝수의 합 초기화 int evenSum =0; // 홀수의 합 초기화 int oddSum=0; // for문을 1부터 10까지 1씩 증가하며 반복한다 for(int i=1; i
1부터 10까지 합계 출력 public class 누적더하기 { public static void main(String[] args) { // sum 초기화 int sum = 0; // for문을 1부터 10까지 1씩 증가하며 반복한다 for(int i=1; i
정수 2개와 연산자 하나를 입력 받아 두 정수의 연산을 출력 연산자: + - * / % 입력 예) 3 2 + 출력 예) 3+2=5 만약 다른 연산자가 들어오면 '잘못된 연산자입니다.' 출력 // Scanner 클래스를 사용하기 위한 import import java.util.Scanner; public class 계산기 { public static void main(String[] args) { // scan 시작 Scanner sc = new Scanner(System.in); System.out.print("첫번째 정수> "); int num1 = sc.nextInt(); System.out.print("두번째 정수> "); int num2 = sc.nextInt(); System.out.print(..
1~6까지의 수를 랜덤으로 추출하여 '주사위 : 1칸 전진' 출력 public class SwitchRandom { public static void main(String[] args) { // 1~6까지의 랜덤 생성 int dice = (int)(Math.random()*6)+1; //랜덤 수에 따른 출력 switch(dice) { case 1: System.out.println("주사위 : "+dice+"칸 전진"); break; case 2: System.out.println("주사위 : "+dice+"칸 전진"); break; case 3: System.out.println("주사위 : "+dice+"칸 전진"); break; case 4: System.out.println("주사위 : "+dic..