Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CORE JAVA [email protected] 3

Answer-1

class PrimeNumbers

{

   public static Void main (String[] args)

   {

       int i =0;

       int num =0;

       //Empty String

       String  primeNumbers = "";

       for (i = 1; 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

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

     }

  }



This post first appeared on GNIITSolution, please read the originial post: here

Subscribe to Gniitsolution

Get updates delivered right to your inbox!

Thank you for your subscription

×