File tree Expand file tree Collapse file tree 4 files changed +157
-0
lines changed
src/main/java/homework/section4 Expand file tree Collapse file tree 4 files changed +157
-0
lines changed Original file line number Diff line number Diff line change
1
+ package homework .section4 ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class FindFutureDate {
6
+
7
+ public static void main (String [] args ) {
8
+ Scanner input = new Scanner (System .in );
9
+ int todayDate , daysElapsed ;
10
+ do {
11
+ System .out .print ("Enter today's day: " );
12
+ todayDate = input .nextInt ();
13
+ } while (todayDate > 6 || todayDate < 0 );
14
+
15
+ System .out .print ("Enter the number of days elapsed since today: " );
16
+ daysElapsed = input .nextInt ();
17
+
18
+ int futureDay = todayDate + daysElapsed ;
19
+ futureDay %= 7 ;
20
+ if (futureDay < 0 ) {
21
+ futureDay += 7 ;
22
+ }
23
+
24
+ System .out .println (
25
+ "Today is " + findDate (todayDate ) + " and the future day is " + findDate (futureDay ));
26
+ }
27
+
28
+ private static String findDate (int date ) {
29
+ switch (date ) {
30
+ case 0 :
31
+ return "Sunday" ;
32
+ case 1 :
33
+ return "Monday" ;
34
+ case 2 :
35
+ return "Tuesday" ;
36
+ case 3 :
37
+ return "Wednesday" ;
38
+ case 4 :
39
+ return "Thursday" ;
40
+ case 5 :
41
+ return "Friday" ;
42
+ default :
43
+ return "Saturday" ;
44
+ }
45
+ }
46
+ }
Original file line number Diff line number Diff line change
1
+ package homework .section4 ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class ISBN {
6
+
7
+ public static void main (String [] args ) {
8
+ Scanner input = new Scanner (System .in );
9
+ System .out .print ("Enter the first 9 digits of an ISBN as integer: " );
10
+ int first9Number = input .nextInt ();
11
+
12
+ int copy = first9Number ;
13
+ int lastNumber = 0 ;
14
+ for (int i = 9 ; i > 0 ; --i ) {
15
+ lastNumber += (copy % 10 ) * i ;
16
+ copy /= 10 ;
17
+ }
18
+ lastNumber %= 11 ;
19
+
20
+ if (lastNumber == 10 ) {
21
+ System .out .println ("The ISBN-10 number is " + String .format ("%09d" , first9Number ) + "%" );
22
+ } else {
23
+ System .out .println ("The ISBN-10 number is " + String .format ("%09d" , first9Number ) + lastNumber );
24
+ }
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package homework .section4 ;
2
+
3
+ import java .util .Random ;
4
+
5
+ public class RandomMonth {
6
+
7
+ public static void main (String [] args ) {
8
+ Random r = new Random ();
9
+ int randomNum = r .nextInt (12 ) + 1 ;
10
+ System .out .print ("The number is: " + randomNum + ", which is " );
11
+ switch (randomNum ) {
12
+ case 1 :
13
+ System .out .println ("January" );
14
+ break ;
15
+ case 2 :
16
+ System .out .println ("February" );
17
+ break ;
18
+ case 3 :
19
+ System .out .println ("March" );
20
+ break ;
21
+ case 4 :
22
+ System .out .println ("April" );
23
+ break ;
24
+ case 5 :
25
+ System .out .println ("May" );
26
+ break ;
27
+ case 6 :
28
+ System .out .println ("June" );
29
+ break ;
30
+ case 7 :
31
+ System .out .println ("July" );
32
+ break ;
33
+ case 8 :
34
+ System .out .println ("August" );
35
+ break ;
36
+ case 9 :
37
+ System .out .println ("September" );
38
+ break ;
39
+ case 10 :
40
+ System .out .println ("October" );
41
+ break ;
42
+ case 11 :
43
+ System .out .println ("November" );
44
+ break ;
45
+ case 12 :
46
+ System .out .println ("December" );
47
+ break ;
48
+ }
49
+ }
50
+ }
Original file line number Diff line number Diff line change
1
+ package homework .section4 ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ public class RankNumber {
6
+
7
+ public static void main (String [] args ) {
8
+ Scanner input = new Scanner (System .in );
9
+ int one , two , three ;
10
+ System .out .print ("Please input the first number: " );
11
+ one = input .nextInt ();
12
+ System .out .print ("Please input the second number: " );
13
+ two = input .nextInt ();
14
+ System .out .print ("Please input the third number: " );
15
+ three = input .nextInt ();
16
+
17
+ if (one > two ) {
18
+ int temp = one ;
19
+ one = two ;
20
+ two = temp ;
21
+ }
22
+ if (one > three ) {
23
+ int temp = one ;
24
+ one = three ;
25
+ three = temp ;
26
+ }
27
+ if (two > three ) {
28
+ int temp = two ;
29
+ two = three ;
30
+ three = temp ;
31
+ }
32
+
33
+ System .out .println ("The rank is: " + one + ", " + two + ", " + three );
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments