(Accept a single input when user chooses options 1-3 and accept 2 inputs for option 4. Selecting 5 will end the program.
WAP a program to print this series : 2 3 4 5 6 7 2 3 4 5 6 2 3 4 5 2 3 4 2 3 2
Write a program that accepts a number and outputs the reverse of the number. (Use a While loop. Why do you need a while loop here and not a FOR loop?)
WAP that accepts salary and computes tax to be paid based on : 0 - 1 lac no tax
1 lac taxed at 25%
Input the name and marks of 25 students and compute the average. Print out the name and average of each student. (You can do this using an array or without using an array)
import java.util.*;
class MenuDriven
{
public static void main(String[] args)
{
boolean exit=false;
Scanner input=new Scanner(System.in);
System.out.println("Enter Number: ");
double num=input.nextDouble();
System.out.println("1 Ceiling");
System.out.println("2 Floor");
System.out.println("3 Absolute");
System.out.println("4 (a+b)^3");
System.out.println("5 Exit");
do{
System.out.print("Enter your choice: ");
int choice=input.nextInt();
switch(choice){
case 1:
System.out.println(Math.ceil(num));
break;
case 2:
System.out.println(Math.floor(num));
break;
case 3:
System.out.println(Math.abs(num));
break;
case 4:
break;
case 5:
exit=true;
System.exit(0);
break;
}
}
while(!exit);
}
}
Java Reverse Number
import java.util.*;
public class ReverseNumber{
public static void main(String [] args){
Scanner input=new Scanner(System.in));
System.out.print("Enter number");
int num= inout.nextInt();
int n = num;
int rev=0;
System.out.println("Number: ");
System.out.println(" "+ num);
for (int i=0; i<=num; i++){
int r=num%10;
num=num/10;
rev=rev*10+r;
i=0;
}
System.out.println("Reversed Number: "+ rev);
}
}