Local
package com.mywork.ex;
public class Local {
String name;
int age;
String sn;
boolean isKorean;
void setLocalInfo(String _name, int _age, String _sn) {
setLocalInfo(_name, _age);
sn = _sn;
isKorean = sn.charAt(7) <= '4' ? true : false;
}
void setLocalInfo(String _name, int _age) {
name = _name;
age = _age;
}
void output() {
System.out.println("이름 : " + name);
System.out.println("나이 : " + age);
System.out.println("주민등록번호 : " + (sn == null ? "없음" : sn));
System.out.println(isKorean ? "한국인" : "외국인" );
}
}
LocalMain
package com.mywork.ex;
public class LocalMain {
public static void main(String[] args) {
Local person1 = new Local();
Local person2 = new Local();
Local person3 = new Local();
person1.setLocalInfo("홍길동", 20, "901215-1234567");
person2.setLocalInfo("응우엔티엔", 21, "911215-6789123");
person3.setLocalInfo("james", 22);
person1.output(); System.out.println("----------");
person2.output(); System.out.println("----------");
person3.output();
}
}
Rect
package com.mywork.ex;
public class Rect {
int width;
int height;
boolean isSquare;
void setFields(int w, int h) {
width = w;
height = h;
isSquare = (w == h) ? true : false;
}
void setFields(int side) {
width = side;
height = side;
isSquare = true;
}
int calcArea() {
return width * height;
}
void output() {
System.out.println("너비 : " + width);
System.out.println("높이 : " + height);
System.out.println("크기 : " + calcArea());
System.out.println(isSquare ? "정사각형" : "직사각형");
}
}
RectMain
package com.mywork.ex;
public class RectMain {
public static void main(String[] args) {
Rect nemo1 = new Rect();
Rect nemo2 = new Rect();
nemo1.setFields(3, 4);
nemo2.setFields(3);
nemo1.output();
nemo2.output();
}
}
RecursiveClass
package com.mywork.ex;
public class RecursiveClass {
static int count = 0;
static void recursive() {
System.out.println("recursive() call");
if(++count == 5) return;
recursive();
}
public static void main(String[] args) {
recursive();
}
}
Triangle
package com.mywork.ex;
public class Triangle {
int width;
int height;
void setFields(int w, int h) {
width = w;
height = h;
}
}