Showing posts with label if. Show all posts
Showing posts with label if. Show all posts

Saturday, 15 June 2013

Demonstration of Nested if in Java

public class Test {

   public static void main(String args[]){
      int x = 30;
      int y = 10;

      if( x == 30 ){
         if( y == 10 ){
         System.out.print("X = 30 and Y = 10");
      }
   }
}

program for if statement OR use of if statement in java

public class Test {

   public static void main(String args[]){
      int x = 10;

      if( x < 20 ){
         System.out.print("This is if statement");
      }
   }
}

Thursday, 13 June 2013

program in java to check given number odd or even ...........

import java.io.*;
class simple_check_odd_or_even
{
    public static void main(String args[])
    {
        try
        {
            int no;
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter nuber to check it possitive or negative");
            no=Integer.parseInt(cin.readLine());
            if(no%2==0)
            {
                System.out.println(no+" is even number");
            }
            else
            {
                System.out.println(no+" is odd number");
            }
        }
        catch(Exception e)
        {
            System.out.println("Wrong data");
        }
    }
}