Wednesday, July 29, 2020

 EXAMPLE OF MENU DRIVEN PROGRAM IN JAVA
-----------------------------------------------------------------------
//To implement Menu driven Program
import java.util.*; // Include Java Packages
public class menu   // Declare the class
{
  public static void main(String args[]) //Main method
  {
      Scanner ob=new Scanner(System.in);
      int a,b,c;                             //Declare the variables
      System.out.println("                          MAIN MENU                        ");     // Main menu
      System.out.println("\t ------------------------------------------------------------");
      System.out.println("\t 1.TO ADD 2 NUMBERS AND DISPLAY THE RESULT");
      System.out.println("\t 2.TO MULTIPLY 2 NUMBERS AND DISPLAY THE RESULT");
      System.out.println("\t 3.TO CALCULATE AVERAGE OF 2 NUMBERS AND DISPLAY THE RESULT");
      System.out.println("\t 4.EXIT");
      System.out.println("\t ENTER YOUR CHOICE");    //input your choice
      int ch=ob.nextInt();
     
     
      switch(ch)
      {
                   
          case 1:                                  //To add 2 numbers
          System.out.println("\n\n");
          System.out.println("\t Enter the numbers");
          a=ob.nextInt();
          b=ob.nextInt();
          c=a+b;
          System.out.println("\n\n");
          System.out.println("\t SUM IS:"+c);     //Display the answer
          break;
         
          case 2:
          System.out.println("\n\n");
          System.out.println("\t Enter the numbers");  //To Multiply 2 numbers
          a=ob.nextInt();
          b=ob.nextInt();
          c=a*b;
          System.out.println("\n\n");
          System.out.println("\t PRODUCT IS:"+c);     //Display the answer
          break;
         
          case 3:
          System.out.println("\n\n");
          System.out.println("\t Enter the numbers");   //To divide 2 numbers
          a=ob.nextInt();
          b=ob.nextInt();
          int k1=0;
          int k2=0;
          if(a==b)
          {
            k1=1;
            k2=0;
          }
          if(a>b)
          {
           k1=a/b;
           k2=a%b;
           }
          else
          {
           k1=b/a;
           k2=b%a;
           }
           System.out.println("\n\n");
           System.out.println("\t QUOTIENT IS:"+k1);     //Display the answers
           System.out.println("\t REMAINDER IS:"+k2);
          
           case 4:
           System.exit(1);
          
           default :
           System.out.println("\t INVALID CHOICE");    //Invalid case
        }  //End of Switch
     
    }  //End of main
}  //End of class

       
         
         
         
         

Tuesday, July 28, 2020

Algorithm :

1. Write an Algorithm to input a number and check whther the number is Odd or Even .

START

Step 1: Input the value of 'N'

Step 2: If N is divisible by 2 then Print N "is  Even Number" else Print "is Odd Number"

END


Monday, September 23, 2019


LIST OF JAVA PROGRAMS related with Conditional Statement 

1. Write a JAVA program to accept two integers and check whether they are equal or not. Test Data : 15 15
Expected Output
:
Number1 and Number2 are equal

2. Write a JAVA program to check whether a given number is even or odd.
Test Data : 15
Expected Output :
15 is an odd integer

3. Write a JAVA program to check whether a given number is positive or negative. Test Data : 15
Expected Output :
15 is a positive number

4. Write a JAVA program to find whether a given year is a leap year or not.
Test Data : 2016
Expected Output :
2016 is a leap year.

5. Write a JAVA program to read the age of a candidate and determine whether it is eligible for casting his/her own vote. Test Data : 21
Expected Output :
Congratulation! You are eligible for casting your vote.

6. Write a JAVA program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.
Test Data : -5
Expected Output :
The value of n = -1

7. Write a JAVA program to accept the height of a person in centimeter and categorize the person according to their height.
Test Data : 135
Expected Output :
The person is Dwarf.

8. Write a JAVA program to find the largest of three numbers.
Test Data : 12 25 52
Expected Output :
1st Number = 12,        2nd Number = 25,        3rd Number = 52
The 3rd Number is the greatest among three

9. Write a JAVA program to accept a coordinate point in a XY coordinate system and determine in which quadrant the coordinate point lies.
Test Data : 7 9
Expected Output :
The coordinate point (7,9) lies in the First quadrant.


10. Write a JAVA program to find the eligibility of admission for a professional course based on the following criteria: Marks in Maths >=65
Marks in Phy >=55
Marks in Chem>=50
Total in all three subject >=180
or
Total in Math and Subjects >=140
Test Data :
Input the marks obtained in Physics :65
Input the marks obtained in Chemistry :51
Input the marks obtained in Mathematics :72
Expected Output :
The candidate is eligible for admission.

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);
    }
 }

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