Thursday 24 July 2014

Calculate square of odd, cube of even , quotient for multiple of 7 with java code.

import javax.swing.*;
class Cal
{
                public static void main(String args[])
                {
                                int n;
                                n = Integer.parseInt(JOptionPane.showInputDialog("enter a value: "));
                                if (n%2==0)
                                {
                                System.out.println("cube of even value = " + n*n*n);
                                JOptionPane.showMessageDialog(null, "cube of even value = " + (n*n*n));
                                }
                                else if (n%2!=0)
                                {
                                System.out.println("square of odd value = " + n*n);
                                JOptionPane.showMessageDialog(null, "square of odd value = " + (n*n));
                                }
                                if (n%7 == 0)
                                {
                                System.out.println("quotient for 7 is " + n/7);
                                JOptionPane.showMessageDialog(null,"quotient for 7 is " + (n/7));
                                }
                                System.exit(0);
                }

}

No comments:

Post a Comment