Friday, March 6, 2009

DivisionPractice

import javac.swing.JoptionPane; ....importing the joption pane pckage to make the work easier

    public class DivisionPractice{  .....the name of the class

    public static void main(String[]args){


    int in1 = JOptionPaneIntegerParseInt(showInputDialog("Enter a numerator:"));  set the numerator that has the data type of int
    int in2 = JOptionPaneIntegerParseInt(showInputDialog("Enter a Divisor;"));  ..set the denominator that has  the data type of  in also...
    int y=n1/n2; ....compute the qoutient
    System.out.println(n1+"/" n2+ \t,"is" +y);...dispaly the output.

                if(in1!=int){ ....iuf the value is not int or any other data type it will give the,...
                System.out.println("enter only an int value");...error message...
                }
                if(n2!=int){ ...if the value of in2 is not an int or any other data type...
                System.out.println("enter only an int value");....error message...
                    }
                if(n1=="q"&&n1=="Q"){ ....if the input is q or Q....
                exit();....exit the program
                    }
                if (n2=="q"&&n2=="Q"){if the input is q or Q....
                exit();....exit the program
                          }    

}
}

No comments:

Post a Comment