Friday, February 22, 2019

 //Program to calculate number of days between 2 dates
 
import java.util.Date;
import java.text.SimpleDateFormat;
class Example 
{
   public static void main(String args[])
   {
  SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
  String d1 = "01 01 2018";
  String d2 = "22 02 2019";

  try {
        Date dateBefore = myFormat.parse(dateBeforeString);
        Date dateAfter = myFormat.parse(dateAfterString);
        long difference = dateAfter.getTime() - dateBefore.getTime();
        float daysBetween = (difference / (1000*60*60*24));
               System.out.println("Number of Days between dates: "+daysBetween);
      }  
        catch (IOException e) 
         {
        System.out.println("Invalid");
  }
   }
}

Thursday, February 7, 2019

//Application of Conditional statement

import java.util.*;
class Prog
{
  public static void main(String args[ ] )
   {
      Scanner ob=new Scanner(System.in);

      int x,y;

      System.out.print("Enter the numbers:");
      x=ob.nextInt( );
      y=ob.nextInt( );

     if(x = =y)
      System.out.println("Both numbers are equal");

     if(x>y)
       System.out.println(x+"is largest");
     else
      System.out.println(y+" is largest");
   }
}
 



Wednesday, February 6, 2019

To Swap 2 numbers

 //To swap 2 numbers

import java.util.*;

class Prog
{
  public static void main(String args[ ])
  {
    Scanner ob =new Scanner (System.in);

    System.out.print("Enter the numbers:");
    int x=ob.nextInt( ) ;
    int y=ob.nextInt( ) ;

   System.out.println("Before Swapping value of  First variable :"+x);
   System.out.println("Before Swapping value of  Second variable :"+y);


   y=y+x - (x=y);

   System.out.println("After Swapping value of  First variable :"+x);
   System.out.println("After Swapping value of  Second variable :"+y);

   }

}





Tuesday, February 5, 2019

Java Program :

import java.util.*;

class Prog
{
  public static void main(String args[])
   {
       Scanner ob=new Scanner(System.in);

        int x,y;

       System.out.println("enter  the numbers:");
       x=ob.nextInt( );
       y=ob.nextInt( );
      int z=x+y;
      System.out.println("sum is:"+z);
    }
 }
This is my Blog,Amitabha Sir

  3.WAP IN JAVA TO INPUT THREE NUMBERS AND COUNT HOW MANY OF THEM ARE EVEN .   import java.util.*; class Prog {   public static ...