Computer Science, asked by gurjargeetansh1, 6 months ago

write a Java program to accept the choice from the user and display the following output
1. To find the number is even or odd.
2. To find the number is prime or not.
3. To find cube root of a number.
for any other choice display "INVALID CHOICE"​
please answer it as fast you can​

Answers

Answered by udayagrawal49
0

Answer:

1) Java program to find the number is even or odd :-

import java.util.Scanner;

public class oddEven {

public static void main(String[] args) {

 try {

  Scanner scan = new Scanner(System.in);

  int num = scan.nextInt();

  scan.close();

  if (num % 2 == 0)

   System.out.println(num+" is an even number.");

  else

   System.out.println(num+" is an odd number.");

 }

 catch(Exception e){

  System.out.println("INVALID CHOICE");

 }

}

}

2) Java program to find the number is prime or not :-

import java.util.Scanner;

public class primeNum {

public static void main(String[] args) {

 try {

  Scanner scan = new Scanner(System.in);

  int num = scan.nextInt();

  scan.close();

  boolean flag = false;

  for (int i = 2; i <= num/2; ++i) {

   if (num % i == 0) {

    flag = true;

    break;

   }

  }

  if (!flag)

   System.out.println(num+" is a prime number.");

  else

   System.out.println(num+" is not a prime number.");

 }

 catch(Exception e){

  System.out.println("INVALID CHOICE");

 }

}

}

3) Java program to find cube root of a number :-

import java.util.Scanner;

public class cubeRootOfNumber {

public static void main(String[] args) {

 try {

  Scanner scan = new Scanner(System.in);

  int num = scan.nextInt();

  scan.close();

  double cubeRoot = Math.cbrt(num);

  System.out.println("Cube root of "+num+" is "+cubeRoot);

 }

 catch(Exception e){

  System.out.println("Invalid choice");

 }

}

}

Please mark it as Brainliest.

Similar questions