Tuesday, 16 January 2018

Program to show that entered number is Even or Odd

Source Code :

//Program to show that entered number is Even or Odd

import java.util.*;

class evenOdd
{
    public static void main(String args[])
    {
        int no;
        Scanner sc = new Scanner(System.in);       
        System.out.print("\n Enter Any Integer : ");
        no=sc.nextInt();

        if(no%2==0)
        {
             System.out.println("\n Even ");
        }
        else
        {
             System.out.println("\n Odd ");
        }
    }
}

Output Screen : 


WAP to accept number and find its factorial

Source Code :

//program to accept number and find its factorial

import java.util.*;

public class factorial
{
  public static void main(String args[])
  {
     Scanner sc=new Scanner(System.in);
     int no,fact=1,i;

     System.out.print("\n Enter no to find its factorial : ");
     no=sc.nextInt();

     for(i=1;i<=no;i++)
     {
       fact=fact*i; 
     }

     System.out.println("\nFactorial of "+no+" is "+fact);
  }
}

Output Screen :

Program to print "Hello World !!!" on console

Source Code : 

// simple java program for printing hello world

public class simple
{
 public static void main(String args[])
 {
  System.out.print("Hello World !!! \n");
 }
}

Output Screen :