ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 이것이 자바다 | 4강_연습문제
    JAVA/이것이 자바다 2022. 1. 24. 01:02

    4강 연습문제1

    package chap04;
    
    public class Exercise03{
    	public static void main(String[] args) {
    		int sum = 0;
    		
    		for (int i = 1; i <= 100; i++) {
    			if ((i % 3) == 0)
    				sum += i;
    		}
    		System.out.println("3의 배수의 합: " + sum);
    	}
    }

     

    4강 연습문제2

    package chap04;
    
    public class Exercise04 {
    	public static void main(String[] args) {
    		int dot1, dot2;
    		do {
    		dot1 = (int)(Math.random()*5) + 1;
    		dot2 = (int)(Math.random()*5) + 1;
    		System.out.println("("+dot1+","+dot2+")");
    		} while((dot1 + dot2) != 5);
    	}
    }

     

    4강 연습문제3

    package chap04;
    
    public class Exercise05 {
    	public static void main(String[] args) {
    		for(int x = 1; x <= 10; x++) {
    			for(int y = 1; y <= 10; y++) {
    				if ((4*x + 5*y) == 60)
    					System.out.println("("+x+","+y+")");
    			}
    		}
    	}
    }

     

    4강 연습문제4

    package chap04;
    
    public class Exercise06 {
    	public static void main(String args[]) {
    		for(int i = 0; i < 5; i++) {
    			for(int j = 0; j < i + 1; j++) {
    				System.out.print('*');
    			}
    			System.out.println("");
    		}
    	}
    }

     

    4강 연습문제5

    package chap04;
    
    import java.util.Scanner;
    
    public class Exercise07 {
    	public static void main(String[] args) {
    		boolean run = true;
    		
    		int balance = 0;
    		
    		Scanner scanner = new Scanner(System.in);
    		
    		while(run) {
    			System.out.println("_______________________");
    			System.out.println("1.예금 | 2.출금 | 3.잔고 | 4.종료");
    			System.out.println("_______________________");
    			System.out.print("선택> ");
    			
    			int menuNum = scanner.nextInt();
    			switch(menuNum) {
    				case 1:
    					System.out.print("예금액>");;
    					balance += scanner.nextInt();
    					break;
    				case 2:
    					System.out.print("출금액>");
    					balance -= scanner.nextInt();
    					break;
    				case 3:
    					System.out.println("잔고>" + balance);
    					break;
    				case 4:
    					run = false;
    			}
    		}
    		System.out.println("프로그램 종료");
    	}
    }
Designed by Tistory.