uNreQuiteD

January 16, 2007

if: odd or even

Filed under: basic java — anai lem @ 11:15 am

import javax.swing.*;
class evenOdd
{
  public static void main(String args[])
  {
  int num = Integer.parseInt(JOptionPane.showInputDialog(“Enter a number”));
  int abs=num;

  if(num<0)
     abs *= -1;

  int sqr = num * num;

  if(num % 2 == 0)
    JOptionPane.showMessageDialog(null,num +” is even\nSquared value = ” + sqr);
  else
    JOptionPane.showMessageDialog(null,num +” is odd\nAbsolute value = ” + abs);
  }
}

output

 p.jpg

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a comment

Blog at WordPress.com.