Write a Java Program to accept number of week's day (1-7) and print name of the day


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Scanner;
  2. public class JavaExcercise {
  3.  
  4. public static void main(String[] args)
  5. {
  6. Scanner in = new Scanner(System.in);
  7. System.out.print("Input number: ");
  8. int day = in.nextInt();
  9.  
  10. if(day == 1)
  11. {
  12. System.out.println("Monday");
  13. }
  14. else if(day == 2)
  15. {
  16. System.out.println("Tuesday");
  17. }
  18. else if(day == 3)
  19. {
  20. System.out.println("Wednesday");
  21. }
  22. else if(day == 4)
  23. {
  24. System.out.println("Thursday");
  25. }
  26. else if(day == 5)
  27. {
  28. System.out.println("Friday");
  29. }
  30. else if(day == 6)
  31. {
  32. System.out.println("Saturday");
  33. }
  34. else if(day == 7)
  35. {
  36. System.out.println("Sunday");
  37. }
  38. else
  39. {
  40. System.out.println("Invalid Input! Please enter week number between 1-7.");
  41. }
  42.  
  43. }
  44. }

Result

java techstudy.org

     





Related Topics




Popular Posts