Days in a Month Exercise
Additional Exercises
//Exercise 2: try to create a program to find the number
//of days in a month
//input a month number and year
//outputs how many days that month, year has
//hints: think about how many days each month has
//split them into dif. days in a month
import java.util.Scanner;
public class Main {
private static String[] words = {"words", "to", "put", "in"};
private static String word = words[(int) (Math.random() * words.length)];
private static String asterisk = new String(new char[word.length()]).replace("\0","*");
private static int count = 0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//create a while loop when count is less than 7 and
//when asterisk contains *
while (count < 7 && asterisk.contains("*")) {
//print guess any letter in the word
//print asterisk
//take in guess and scan it in (string guess and take in scan)
//hang(guess)
System.out.println("Guess any letter in the word");
System.out.println(asterisk);
String guess = sc.next();
hang(guess);
}
sc.close();
}}
import java.util.Scanner;
public class Main {
public static void main(String[] strings) {}}
Scanner input = new Scanner(System.in);
int number_Of_DaysInMonth = 0;
String MonthOfName = "Unknown";
System.out.print(" Input a month number: ");
int month = input.nextInt();
System.out.print(month);
System.out.print(" Input a year: ");
int year = input.nextInt();
System.out.print(year);
switch (month) {
case 1:
MonthOfName = "January";
number_Of_DaysInMonth = 31;
break;
case 2:
MonthOfName = "February";
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
number_Of_DaysInMonth = 29;
} else {
number_Of_DaysInMonth = 28;
}
break;
case 3:
MonthOfName = "March";
number_Of_DaysInMonth = 31;
break;
case 4:
MonthOfName = "April";
number_Of_DaysInMonth = 30;
break;
case 5:
MonthOfName = "May";
number_Of_DaysInMonth = 31;
break;
case 6:
MonthOfName = "June";
number_Of_DaysInMonth = 30;
break;
case 7:
MonthOfName = "July";
number_Of_DaysInMonth = 31;
break;
case 8:
MonthOfName = "August";
number_Of_DaysInMonth = 31;
break;
case 9:
MonthOfName = "September";
number_Of_DaysInMonth = 30;
break;
case 10:
MonthOfName = "October";
number_Of_DaysInMonth = 31;
break;
case 11:
MonthOfName = "November";
number_Of_DaysInMonth = 30;
break;
case 12:
MonthOfName = "December";
number_Of_DaysInMonth = 31;}
System.out.print(" " + MonthOfName + " " + year + " has " + number_Of_DaysInMonth + " days\n");