-
생일, 성년일(Class, toString)코딩/java 2019. 1. 2. 17:08반응형
public class Date {
int year;
int month;
int date;
public String toString() {
//return(year + "년" + month + "월" + date + "일");
String rslt;
rslt = year + "년" + month + "월" + date + "일";
return rslt;
}
}
import java.util.Scanner;
public class Practice_41 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Date birthday = new Date();
Date adultday = new Date();
System.out.print("태어난 년도를 입력하세요: ");
birthday.year = input.nextInt();
System.out.print("태어난 월을 입력하세요: ");
birthday.month = input.nextInt();
System.out.print("태어난 날짜를 입력하세요: ");
birthday.date = input.nextInt();
adultday.year = birthday.year + 20;
adultday.month = birthday.month;
adultday.date = birthday.date;
String s1 = birthday.toString();
String s2 = adultday.toString();
System.out.println("당신의 생일은 " + s1 + "입니다.");
System.out.println("당신의 성년일은 " + s2 + "입니다.");
input.close();
}
}
결과:
반응형'코딩 > java' 카테고리의 다른 글
생일, 성년일 계산(설정자 사용) (0) 2019.01.02 사각형 면적, 둘레 계산(Class) (0) 2019.01.02 생일, 성년일(Class) (0) 2019.01.02 나이가 중간인 사람 계산 (0) 2019.01.02 비행기 정보 출력(입력 없음) (0) 2018.11.27