View Single Post
  #1 (permalink)  
Old 01-26-2008, 06:16 AM
Deon's Avatar
Deon Deon is offline
Member
 
Join Date: Jan 2008
Posts: 12
Deon is on a distinguished road
Need help on Exception
Output i must get







When i type in the Letters i get "Please enter positive integer values only" instead of "Please enter in numbers, not letters"

i just can't slove it


PHP Code:
import javax.swing.JOptionPane;
import java.util.InputMismatchException;

public class 
Chapter8Q2
{
   public static 
void main String[] args ) {
    
    
int age ;
    
String message1 "Please enter your age in years" "\n";
    
String message3 "Please enter positive integer values only""\n";
    
String message4 "Please enter in numbers, not letter""\n";
    
String temp ,outputMessage ;

try{

    
temp JOptionPane.showInputDialog(message1);
    
age Integer.parseInt(temp);
    
    if( 
age 0)
        throw new 
IllegalArgumentException();
    
outputMessage "Your age is "age " years""\n";
    
JOptionPane.showMessageDialog(nulloutputMessage);
    
}
//end try


catch( InputMismatchException e)    //non number
{
    
JOptionPane.showMessageDialog(nullmessage4);
}
//end catch


catch( IllegalArgumentException e)    //negative number
{
    
JOptionPane.showMessageDialog(nullmessage3);

}
//end catch


System.exit(0);

}
//main
}//class 
__________________
I LOVE JAVA!
Reply With Quote
Sponsored Links