Hi. Can someone help me figure out what is wrong with the JOptionPane.showMessageDialog box? The program was working fine until i used JOptionPane. Its showing me the input but not the messages..
p.s. I am using Eclipse
-----------------------------------
package Assigments;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class DaysInMonth {
public static void main(String[] args) {
// create a Scanner
Scanner input = new Scanner(System.in);
int numMonths = Integer.parseInt (JOptionPane.showInputDialog("Enter a Month:"));
//String month = JOptionPane.showInputDialog("Enter a Month:");
JOptionPane.showInputDialog("Enter a Year:");
int year = input.nextInt();
int[] myList = {31,28,31,30,31,30,31,31,30,31,30,31};
//Check if the year is a leap year
boolean isLeapYear=
(year % 4 == 0 && year % 100 !=0)||(year % 400 == 0);
// if leap year is true then check for the month and display number of days
if(isLeapYear){
if (numMonths==2)
{
JOptionPane.showMessageDialog(null,numMonths + "/" + year + " has 29 days");
}
else{
JOptionPane.showMessageDialog(null,numMonths + "/" + year + " " + myList[numMonths-1] + " days. ");
}}
else{
JOptionPane.showMessageDialog(null,numMonths + "/" + year + " " + myList[numMonths-1] + " days. ");
}
//Display the result
Comments
The program has good syntax to retrieve the numMonths. The same "pattern" needs to be followed to retrieve year.
Replace statements
[code]JOptionPane.showInputDialog("Enter a Year:");
int year = input.nextInt();[/code]
with code similar to that used for numMonths and it will work like a champ.