<aside> πŸ“Œ 2024 - 01 - 03 (수)

</aside>

MyFrame.java

package ch04;

import java.awt.Button;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyFrame extends Frame {  
	
	public MyFrame() {
		setSize(300,300);
		setBackground(setColor());
		Button btn = new Button("myButton");
		
		btn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				setBackground(setColor());
			}
		});
		add(btn,"South");
		
		setVisible(true);
	}

	public static void main(String[] args){
	
		new MyFrame();
	}
	
	public Color setColor() {
		int r = (int)(Math.random()*256);
		int g = (int)(Math.random()*256);
		int b = (int)(Math.random()*256);
		return new Color(r,g,b);
	}

}
package ch04;

import java.util.Scanner;

public class Ex3 {

	public static void main(String[] args) {
		
		//μž…λ ₯ν•œ 1~20μ‚¬μ΄μ˜ μˆ«μžμ€‘μ— 3, 6, 9인지λ₯Ό νŒλ‹¨ν•˜μ„Έμš”.
				Scanner sc = new Scanner(System.in);
				System.out.println("3,6,9κ²Œμž„ 숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”.");
				int a = sc.nextInt();
				
				if((a==3) && (a==6) && (a==9)) {
					System.out.println("짝");
				} else if((a>=10) && (a%3==1)){
					System.out.println("짝");
				} else{
					System.out.println(a);
				}// --if-else				
}
}