<aside> π 2024 - 01 - 03 (μ)
</aside>
METHOD λ€μ ν¨μ μ 무 μ°¨μ΄ μκΈ°
args λ» ?
Test.java (λͺ¨λ νμΌλ‘ μ€μ )
ν΄λμ€ μ²« κΈμλ λλ¬Έμ
// System.out.println("μ λ ₯νμ κ°μ" s "μ λλ€."); ν΄κ²°νκΈ°! (νκΈ μ¬μ΄ λ³μ)
abs - μ λκ° κ΅¬νλ λ©μλ
μμ μΆμΆ μ½λ ( frame = μλμ° μλ―Έ )
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);
}
}
java νμΌ λͺ μ f^2 λ²νΌμ λλ₯Ό μ μ΄λ¦ λ³κ²½ κ°λ₯
λ΄κ° ν 3 6 9
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
}
}