Tuesday 27 September 2016

CORE JAVA LAB@HOME 3 ~ GNIITHELP

Answer-1

class PrimeNumbers

{

   public static void main (String[] args)

   {

       int i =0;

       int num =0;

       //Empty String

       String  primeNumbers = "";

       for (i = 1; i <= 100; i++)         

       {       

          int counter=0;    

          for(num =i; num>=1; num--)

  {

             if(i%num==0)

     {

  counter = counter + 1;

     }

  }

  if (counter ==2)

  {

     //Appended the Prime number to the String

     primeNumbers = primeNumbers + i + " ";

  }

       }

       System.out.println("Prime numbers from 1 to 100 are :");

       System.out.println(primeNumbers);

   }

}


Answer-2


public class DivisibleChecker {

  

  public static void main(string [] args) {

   int num1, num2;

   num1 = 32;

   num2 = 12;

   if (num1 % num2 == 0) {

        System.out.println("The first number is divisible by the second number");

   } else {

    System.out.println("The first number is not divisible by the second number");

   }

  }

 }

Answer-3

public class table {

  public static void main(String [] args)

  int result;

  

   for (int i = 1; i <=10; i++) {

    result = i * 5;

  system.out.println("5 * " + i " = " + result);

   }

 }

 } 

Answer-4


public class EmployeeDetails {

     public void showMenue ()  {

         int option;

         System.out.println("------------Menu--------");

         System.out.println("1. Enter Data");

         System.out.println("2. Display Data");

         System.out.println("3. Exit");

         System.out.println("\nChoose the option:  ");

         Option = 2;

  switch (option)  {

  case 1:

   enterData();

   break;

  case2:

   DisplayData();

   break;

  case3:

   exitMenue();

   break;

  defalt:

   System.out.println("Incorrect menu option");

   showMenu();

   break;

    }

  }

  public void enterData() {

   System.out.println("enterData method is invoked");

  }

  public void enterData() {

   System.out.println("displayData method is invoked");

  }

  public void enterData() {

   System.out.println("exitMenu method is invoked");

   System.exit(0);

  }

  public static void main(String[] args)  {

   EmployeeDetails obj = new EmployeeDetails();

   obj.showMenu();

     }

  }

No comments:

Post a Comment