forked from google/codeu_coding_assessment_2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendar.java
More file actions
53 lines (51 loc) · 1.66 KB
/
Calendar.java
File metadata and controls
53 lines (51 loc) · 1.66 KB
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
53
import java.util.*;
public class Calendar {
public static void main(String args[]){
System.out.println("Please enter the number of days in the month: ");
Scanner days = new Scanner(System.in);
int days = days.nextInt();
System.out.println("Please enter the number of the day of the first Sunday: ");
int firstsunday = days.nextInt();
printfirst(firstsunday);
printbottom(firstsunday, days);
System.out.println("+------------------------------------------------+");
}
public static void printbottom(int firstsunday, int numberofdays){
int count = firstsunday;
int fincount = count;
for(int i = 0; i <= (int)Math.ceil(((numberofdays-firstsunday+1)/(7.0))-1); i++){
for(int j = count; j < firstsunday + (i+1)*7;j=j){
System.out.print("| ");
if(j-10<0){
System.out.print(" ");
}
int county = j;
String countx = " ";
if(j>numberofdays){
System.out.print(countx);
}else if(j <= numberofdays){
System.out.print(county);
}
System.out.print(" ");
count = j + 1;
j += 1;
}
System.out.print("|");
System.out.println("");
}
} public static void printfirst(int firstsunday){
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
System.out.println("+------------------------------------------------+");
for(int j = firstsunday - 7; j < firstsunday; j++){
if(j<=0){
System.out.print("| ");
}else if(j>0){
System.out.print("| ");
System.out.print(j);
System.out.print(" ");
}
}
System.out.print("|");
System.out.println("");
}
}