|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package java1;
// 양수 5개를 입력받아 배열에 저장하고, 제일 큰 수를 출력하는 프로그램을 작성하여라,
public class test {
public static void main(String[] args) {
Scanner scanner= new Scanner(System.in);
// 월 - 일 입력
// 월 - 일 부터 1년의 남은 날짜를 계산하는 프로그램
// for- each 사용하지 않기.
int[] days= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int day= 0;
int month= 0;
int user_month=0;
int user_day= 0;
int total_day =0;
int total= 0;
int last_total=0;
// 입력받은 월(인덱스값)-1 을 제거하고 해당 인덱스에서 입력받은 일수만큼 제거.> 나머지값출력 //284
System.out.println("오늘은 몇월달인가요? ");
user_month= scanner.nextInt();
System.out.println("오늘은 며칠인가요? ");
user_day= scanner.nextInt();
for(int i=0; i<(user_month-1); i++) { // 유저가 입력한 값에 -1의 값과 같아질때까지 i를 계속 증가시켜라. 3을 입력했다면 2가 되야함. 인덱스 0(1월) 1(2월)
month+= days[i];} // month에 days의 인덱스i값 증가치만큼 더해라. 이 때 일수로 저장된다. // &&& 여기까지 59일 맞음ㅠㅜㅜㅠㅠㅠㅜ
for(int j=0; j<user_month; j++) { //유저가 입력한 달.3과 j의 값이 같아질떄까지 j를 증가시켜서, j를 days의인덱스 값에 넣는다.
day= days[j]; // &&&여기까지 31일 맞음 ㅠ후ㅠㅜㅜㅜㅜㅜㅠㅠㅠ
}
for(int k=0; k<days.length; k++) { // 총 일수의 합에서 앞서 계산한것들을 뺴줘야하니까 총 일수 계산
total_day +=days[k]; // ㅁㄴㅇㅁㄴㅇㅁㄴ 여기까지 365일 맞으ㅜㅁㅠㅜㅠㅠㅠㅠ
}
total= month+user_day; // 59일+15 = 74
last_total= total_day-total; // 365 - 유저가입력한달의수,일의수
System.out.print("남은 일수는"+last_total+" "+total);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
카테고리 없음