WAP to print the result based on the user’s choice;
Choices:
1. Enter 1 to print the Square root of any number
2. Enter 2 to print the Square of any number.
3. For any other choices system should give an output as- “invalid input”.
please answer fast it's urgent
Answers
Answered by
1
import java. util. Scanner;
public class wap
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in) ;
System. out. print("Enter your choice: ") ;
int choice=sc.nextInt() ;
switch(choice)
{
case 1:
System. out. print("Enter a number: ") ;
double a= sc. nextDouble() ;
double sqrt=Math.sqrt(a) ;
System. out. println("The square root is :"+sqrt) ;
break;
case 2:
System. out. print("Enter a number: ") ;
double b= sc. nextDouble() ;
double square=Math.pow(b, 2) ;
System. out. println("The square root is :"+square) ;
break;
default:
System. out. println(" Invalid choice") ;
}
}
}
Similar questions