0

Could someone give me the program for this question Input a number between 1 and 7 and print out the corresponding day of the week Sample input = 6 Sample output= saturday Thank

20th Nov 2016, 2:50 PM
David
2 Réponses
+ 1
Java Syntax Ahead: import java.util.Scanner; public class DaysOfTheWeek{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Type a number from 1 to 7: "); String input = scan.nextLine(); if(input.equals("1")){ System.out.println("Monday"); }else if(input.equals("2")){ System.out.println("Tuesday"); }else if(input.equals("3")){ System.out.println("Wednesday"); }else if(input.equals("4")) { System.out.println("Thursday"); }else if(input.equals("5")){ System.out.println("Friday"); }else if(input.equals("6")) { System.out.println("Saturday"); }else if(input.equals("7")){ System.out.println("Sunday"); }else{ System.out.println("Please type a number between 1 to 7"); } } } //please upvote if you find it interesting //================================================================ //Next Method Using Switch Statement import java.util.Scanner; public class DaysOfTheWeekSwitch{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Type a number from 1 to 7: "); String input = scan.nextLine(); switch(input){ case "1": System.out.println("Monday"); break; case "2": System.out.print("Tuesday"); break; case "3": System.out.println("Wednesday"); break; case "4": System.out.println("Thursday"); break; case "5": System.out.println("Friday"); break; case "6": System.out.println("Saturday"); break; case "7": System.out.println("Sunday"); break; default: System.out.println("please Type a number between 1 to 7"); } } }
20th Nov 2016, 4:08 PM
( ͡° ͜ʖ ͡°)
0
Nice one pal
20th Nov 2016, 5:35 PM
David