Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners programes on switch

Have Programming Question? Ask it here!
 
 
 


Amit
programes on switch
2 Answer(s)      3 years and a month ago
Posted in : Java Beginners


  1. write a program to design menu driven arithmetic calculator
  2. write a program to print no of days in a given month

Advertisement
View Answers

March 26, 2011 at 1:22 PM


import java.util.*;
class Calculator
{
    public static void main(String[] args) 
    {
        boolean exit=false;
        Scanner input=new Scanner(System.in);
        System.out.print("Enter number1: ");
        double num1=input.nextDouble();
        System.out.print("Enter number2: ");
        double num2=input.nextDouble();
        System.out.println("1 Addition");
        System.out.println("2 Subtraction");
        System.out.println("3 Multiplication");
        System.out.println("4 Division");
        System.out.println("5 Exit");
        do{
            System.out.print("Enter your choice: ");
            int choice=input.nextInt();
            switch(choice){
                case 1: 
                    double add=num1+num2;
                    System.out.println("Addition="+add);
                    break;
                case 2: 
                    double sub=num1-num2;
                    System.out.println("Subtraction="+sub);
                    break;
                case 3: 
                    double mul=num1*num2;
                    System.out.println("Multiplication="+mul);
                    break;
                case 4: 
                    double div=num1/num2;
                    System.out.println("Division="+div);
                    break;
                case 5: 
                    exit=true;
                    break;
            }
        }
        while(!exit);
    }
}


March 26, 2011 at 1:24 PM




Related Tutorials/Questions & Answers:
programes on switch
programes on switch   write a program to design menu driven arithmetic calculator write a program to print no of days in a given month   ...=input.nextInt(); switch(choice){ case 1
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
Advertisements
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on for loop
programes on for loop  a. write a program to find squares and cubes of 1st 10 integers b. write a program to to calculate factorial of a no, c. write a program to print Fibonacci series d. write a program to check whether entered
programes on methods
programes on methods   write a program to implement bubble sort write a program to demonstrate call by value and call by reference.(pass objects as parameters) write a program to calculate factorial of a no. using recursive
programes on strings
programes on strings   a. write a program to copy one array to another array using System.arrayCopy() method. b. write a program to check whether entered string is palindrome or not.   Have a look at the following link
programes on array
programes on array  a. write a program to find max and min element in an array of an integer b. write a program to convert decimal no. to binary... choice: "); menu = input.nextInt(); System.out.println(); switch(menu) { case 1
programes on if....else
programes on if....else   write a program to check whether entered year is leap year or not write a program to check whether entered no. ends with 5 or not write a program to find minimum of 3 nos using nested if else. write
programes on while loop
programes on while loop   write a program to calculate sum of an entered digit write a program to find gcd and lcm of 2 positive integers   Java sum of digits Java Find LCM and GCD
programes on do... while
programes on do... while   write a program to print reverse of a given digit write a program to check whether entered digit is palindrome or not write a program to check whether entered no. is Armstrong or not   1
Switch
Switch      ... statements. To avoid this we can use Switch statements in Java. The switch statement... of a variable or expression. The switch statement in Java is the best way to test
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
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
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
Switch databases
Switch databases  How do you inter-change between relational databases without code changes
The Switch statement
Switch       Sometimes.... To avoid this we can use Switch statements in Java. The switch statement is used... of a variable or expression. The switch statement in Java is the best way to test
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
Switch Statement with Strings in Java
Switch Statement with Strings in Java  Switch Statement with Strings in Java
Java switch statement
Java switch statement  What restrictions are placed on the values of each case of a switch statement
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 statement in PHP
Switch statement in PHP  HII, Explain about switch statement in PHP?   hello, Switch statement is executed line by line. PHP executes the statement only when the case statement matches the value of the switch
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
Switch case + condition??
Switch case + condition??  I try to use a switch case with condition but it doesn't display anything have look: ......public void commandAction...(); } } else { List down = (List)display.getCurrent(); switch
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 in Jsp page
Switch case in Jsp page  <table> <tr><td>Enter Distance :</td> <td><input type="text" name="dis"/></td>... using switch case in jsp page
switch functions - Java Beginners
switch functions  I am writing a script for use in a computer based... your month of hire:") switch(n) { case(n="January"): document.write("Last... friend, This is running code, switch option using in javaSctipt
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 Java Keyword
switch Java Keyword       The switch is a keyword defined in the java programming language. Keywords... in java programming language likewise the switch keyword indicates the following
switch CAPSLOCK button in my progranm...
switch CAPSLOCK button in my progranm...  I found that function which does the Capslocks job,when am running my program if the capslock button... the capslocks switch button to become a button that i can switch it between on and off
Switch Statement example in Java
Switch Statement example in Java    ... for implementing the switch statement. Here, you will learn how to use the switch statement... more about the switch statement in Java. The following java program tells you
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
switch Statement - Overview
Java Notes switch Statement - Overview Purpose of switch: select one of many possible statements to execute... on a boolean value (only two possible values). The switch statement allows
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
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
Java Switch Statement
Java Switch Statement       In java, switch is one of the control statement which turns the normal flow... then switch statement can be used. It checks your choice and jump on that case label
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... if statement, switch allow the user to select a option from multiple options
Switch Case in Java
if-then and if-then-else statements. As switch statement allows in-numerous possible execution paths.... Switch statements with String cases are supported in Java SE 7 but the earlier version of Java did not support String in switch/case. Switch statements works
What is the difference between an if statement and a switch statement?
What is the difference between an if statement and a switch statement?   Hi, What is the difference between an if statement and a switch statement... values). Whereas the Switch statement offers you multiple choice of option from
Strings in Switch statement
Strings in Switch statement In this section, you will learn about strings in switch statements which is recently added feature in Java SE 7. Using JDK 7, you can pass string as expression in switch statement. The switch statement
Java - The switch construct in Java
Java - The switch construct in Java       Switch is the control statement in java which... same as If-Else construct. This is the difference between Switch and If-Else
Mysql Switch CASE
Mysql Switch CASE       Mysql Switch Case perform one of several different actions based on several... an example from 'Mysql Switch Case'.To understand an example from 'Mysql Switch
C Break with Switch statement
C Break with Switch statement   ... with Switch-Case in C. The switch case statements allows to control complex... the user to enter any number. The expression defined in the switch statement finds
save switch data into database - Java Beginners
save switch data into database  switch(menu) { case 1://add a student System.out.print("Enter student ID: "); int ID = scan.nextInt...(); switch(menu) { case 1: System.out.print("Enter student ID: "); int ID
How to use switch statement in jsp code
How to use switch statement in jsp code       switch is a type of control statement used to control the flow of program execution. Its body is known as a switch block
iPhone Switch Changes Toolbar Color
iPhone Switch Changes Toolbar Color In this tutorial we will use Switch button to change the Color of Toolbar. The Switch is added through the Interface..., first will declare the variable for the Toolbar, Switch and then will write
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
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
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
 

 

 

DMCA.com