iSay_gotoofar
Posted by donabel malagamba on Friday, July 8, 2011
Under: Copro2
import javax.swing.*;
public class GoTooFar {
public static void main(String[] args)throws ArithmeticException {
int arr1 [] = new int [5];
int num;
try{
for (int x = 0; x < 5; x++){
String xnum = JOptionPane.showInputDialog(null, "Enter number: ");
num = Integer.parseInt(xnum);
arr1 [x] = num;
}
String xnum = JOptionPane.showInputDialog(null, "Enter number From 0 - 4 : ");
num = Integer.parseInt(xnum);
if ((num >= 1) && (num <= 4)){
JOptionPane.showMessageDialog(null, "Index " +num +" has the value " + arr1[num] +".");
}
else{
JOptionPane.showMessageDialog(null,"Your number must be within the range of 0 - 4.");
throw new ArithmeticException();
}
}
catch (ArithmeticException e){
JOptionPane.showMessageDialog(null, "Now You Have Gone too far!");
}
catch (NumberFormatException e){
JOptionPane.showMessageDialog(null, "Only numbers are valid.");
}
finally{
JOptionPane.showMessageDialog(null, "Goodbye!");
}
}
}
public class GoTooFar {
public static void main(String[] args)throws ArithmeticException {
int arr1 [] = new int [5];
int num;
try{
for (int x = 0; x < 5; x++){
String xnum = JOptionPane.showInputDialog(null, "Enter number: ");
num = Integer.parseInt(xnum);
arr1 [x] = num;
}
String xnum = JOptionPane.showInputDialog(null, "Enter number From 0 - 4 : ");
num = Integer.parseInt(xnum);
if ((num >= 1) && (num <= 4)){
JOptionPane.showMessageDialog(null, "Index " +num +" has the value " + arr1[num] +".");
}
else{
JOptionPane.showMessageDialog(null,"Your number must be within the range of 0 - 4.");
throw new ArithmeticException();
}
}
catch (ArithmeticException e){
JOptionPane.showMessageDialog(null, "Now You Have Gone too far!");
}
catch (NumberFormatException e){
JOptionPane.showMessageDialog(null, "Only numbers are valid.");
}
finally{
JOptionPane.showMessageDialog(null, "Goodbye!");
}
}
}
In : Copro2