Sushmita
using switch case
1 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners

Define a class MENU to perform the following operation depending upon the users choice using switch case 1)print square root of the number 2)print rounded down value of a number(in decimals) 3)print rounded up value of a number(in decimals) 4)Quit

Ads

View Answers

February 16, 2012 at 5:11 PM


import java.util.*;
class Menu 
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter Number: ");
        double num=input.nextDouble();
        System.out.println("1 Print Square Root");
        System.out.println("2 Rounded down");
        System.out.println("3 Rounded Up");
        System.out.println("4 Quit");

        System.out.print("Enter your choice: ");
        int choice=input.nextInt();
        switch(choice){
         case 1:
             System.out.println("Square Root of "+num+" is: "+(Math.sqrt(num)));
             break;

         case 2:
             System.out.println("Rounded Down of "+num+" is: "+(Math.ceil(num)));
             break;

         case 3:
             System.out.println("Rounded Up of "+num+" is: "+(Math.floor(num)));
             break;

         case 4:
             System.exit(0);
             break;
        }
    }

}









Related Tutorials/Questions & Answers:
using switch case
using switch case  Define a class MENU to perform the following operation depending upon the users choice using switch case 1)print square root... choice: "); int choice=input.nextInt(); switch(choice
switch case
switch case  program to input 2 numbers and a choice.Using switch case we need to perform all the mathematical operation.Print a suitable error message if the choice is wrong
Advertisements
switch case
switch case  program to input 2 numbers and a choice.Using switch case we need to perform all the mathematical operation.Print a suitable error message if the choice is wrong
Write a java program to display the season given the month using switch case
Write a java program to display the season given the month using switch case  Write a java program to display the season given the month using switch case
Find Capital using Switch-Case statement
Find Capital using Switch-Case statement In this Java Tutorial section, we are going to find the capital of our states using Switch-Case statement. For this, we have created two arrays i.e. array of states and array of capitals. Then we
switch case instead of if else
switch case instead of if else  How to write code in switch case instead of if else in Java
Switch case in Jsp page
using switch case in jsp page...Switch case in Jsp page  <table> <tr><td>Enter Distance :</td> <td><input type="text" name="dis"/></td>
Switch case + condition??
Switch case + condition??  I try to use a switch case with condition...(); } } else { List down = (List)display.getCurrent(); switch(down.getSelectedIndex()) { case 0: Tambo(); if( label.equals
Switch Case - Java Interview Questions
Switch Case  int x=100000; switch(x) { case 100000: printf("Lacks"); } output= Lacks I want reason why x matches switch case although range for int is in between something -32678 to +32676. Plz give me ans quickly
Switch Case in Java
version of Java did not support String in switch/case. Switch statements works... A statement in the switch block can be labeled with one or more case or default labels... case will take place. Example of Switch Statement in Java: import java.io.
PHP Switch Case
Switch Case Control Structure: Almost every modern language supports switch case control structure. It is similar to if statements. Switch case is useful... should know how the switch case works, in switch case every case is considered
Switch case in java
Switch case in java In this section we will learn about switch case in java..., and java, switch case is used . switch  is a selection control mechanism used... will illustrate the use of switch case in java: import java.util.Scanner; public
Mysql Switch CASE
Mysql Switch CASE       Mysql Switch Case perform one of several different actions based... illustrate an example from 'Mysql Switch Case'.To understand an example from
using switch,break and for loop
using switch,break and for loop  generate a 10 digit number and display the length of longest increasing series
using switch and break
using switch and break  generate a 10 digit number and display the length of longest increasing series
change color of back ground using switch
change color of back ground using switch   how to change back ground color according to day using switch case
i need to replace this if statement code with switch case code
i need to replace this if statement code with switch case code   i need to replace this code with switch case for(int i=0;i<100;i++){ if((i...){ switch(i/j){ case 3: System.out.println ("java
using if and switch stmt - Java Beginners
using if and switch stmt  A cloth showroom has announced... be assumed. Write a program using "switch and if statement" to compute net amount...(); switch(menu) { case 1: System.out.print("Quantity: "); int q1 = scan.nextInt
using case in update statement
using case in update statement  i want to use case in update clause. i have used case in select stmt referring answer in this site. but the same syntax is not working for update stmt.my problem is update emp set case deptno
Switch
. Here is the general form of switch statement: switch (expression){ case 1.... Then there is a code block following the switch statement that comprises of multiple case... on the value of week, using the switch statement. class 
Case-insensitive ordering using Hibernate Criteria.
Case-insensitive ordering using Hibernate Criteria.  What is Case-insensitive ordering in Hibernate Criteria
switch statement
switch statement   i want to write a java program that computes Fibonacci,factorial,string reversal and ackerman using switch case to run as a single program
core java ,io operation,calling methods using switch cases
core java ,io operation,calling methods using switch cases  How to create a dictionary program,providing user inputs using io operations with switch cases and providing different options for searching,editing,storing meanings
Case-insensitive equals using Hibernate Criteria.
Case-insensitive equals using Hibernate Criteria.  How to use Case-insensitive equals with Hibernate Criteria?   The Case Insensitive ignores the case of the latter. It Selects all the records of the table related
Switch Statement
Switch Statement  How we can use switch case in java program ?   Note:-Switch case provides built-in multiway decision statement.It...); switch(days){ case 1: System.out.println("Sunday
Case-sensitive equals using Hibernate Criteria.
Case-sensitive equals using Hibernate Criteria.  How to check for case sensitive equals in Hibernate criteria?   package net.roseindia.main; import java.util.*; import net.roseindia.table.Employee; import
The Switch statement
. Here is the general form of switch statement: switch (expression){ case 1... of week, using the switch statement. class Switch{  .... The appropriate case gets executed when the switch statement evaluates its
C Break with Switch statement
with Switch-Case in C. The switch case statements allows to control complex... the second case i.e odd If you enter the number 6, the switch statement checks... C Break with Switch statement   
Case Java Keyword
switch () { case 1: <statements> break; case 2... Case Java Keyword       The java keyword "case" is used to label each branch in the switch
Case-insensitive search using Hibernate Query Language(HQL).
Case-insensitive search using Hibernate Query Language(HQL).  What is Case-insensitive search using Hibernate Query Language
Java switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch statement

Ads

Advertisement