FIV Lab 04.docx - CS 140 Java PROGRAMMING Lab Report[04 Fall 2019 ID A00250811 Name Steven Perumean Date Write a Java program to receive numerical value

FIV Lab 04.docx - CS 140 Java PROGRAMMING Lab Report[04...

This preview shows page 1 - 4 out of 5 pages.

CS 140 Java PROGRAMMING Fall 2019 Lab Report [04] ID: A00250811 Name Steven Perumean Date 10/06/19 Write a Java program to receive numerical value of month as input and out corresponding month name using if else if statement. Enhance with switch statement as second Java program. Sample Input/Output: Please enter a number (1-12) 8 Month is August CODE: package calendar; import javax.swing.JOptionPane; public class Calendar { public static void main(String[] args ) { int num = Integer. parseInt (JOptionPane. showInputDialog ( "Enter any number equal to or between 1-12 to display the month" )); String months [] = { "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" }; if ( num >= 1 && num <= 12) { System. out .format( "The name of month number %d is %s\n" , num , months [ num -1]); } else { System. out .println( "You have entered an invalid number" ); } } } Instructor : Keng S. Chang [email protected]
Image of page 1
CS 140 Java PROGRAMMING Fall 2019 Instructor : Keng S. Chang [email protected]
Image of page 2
CS 140 Java PROGRAMMING Fall 2019 Deck of Cards Code: import java.util.ArrayList ;
Image of page 3
Image of page 4

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture