Home Discussion Discuss: Switch Statement example in Java

  • progfunwharen September 1, 2011 at 12:43 PM

    how to use switch java

  • flowchartIan Quidato September 6, 2011 at 5:55 AM

    Your program is quite understandable but I think it is better to put also its flowchart. Can you please give me the flowchart of the program because I am planning to have it as my project program. thanks.

  • javaUtkarsh September 8, 2011 at 8:52 PM

    give some more example

  • Switch statementPAUL DAVID DAVIES October 4, 2011 at 11:05 AM

    The switch statement above forms an alternative for the dangling else statement in the famous IF statement.But I think it is the best alternative for giving options or creating menus in substitute of the dangling else statement,just to eliminate many errors that can result from using the IF statement:more so errors during compilation.

  • javamebrahtu hafte November 3, 2011 at 5:43 PM

    write a java statement that display the services used in cafe using switch case

  • java programmingkanaga December 14, 2011 at 4:55 PM

    i want how to use java statments java full packages

  • syntax errorJeff Richard A. Arellano January 22, 2013 at 9:16 AM

    System.out.println("Enetr the number three="+ (x*y)); break; "ENETR"

  • cod (Scanner and case)mohammed January 10, 2012 at 2:28 AM

    System.out.println("1 enter the file name"); System.out.println("2 Display the text"); System.out.println("3 Search within the text"); System.out.println("4 Exit");

  • GoodAmit January 23, 2012 at 12:36 PM

    Excellent !!!

  • TerribleCam March 9, 2012 at 5:35 AM

    Bad explanation. Proof-reading is always a good thing. The example was way too complicated to simply show how a switch functions.

  • JAVALAV KISHORE March 25, 2012 at 6:45 PM

    Actually I am visiting this site first time and I am very impressed.Thats why I am leaving this comment......

  • HELP!sumit badaya May 24, 2012 at 1:20 PM

    hello sir, grateful for helps in java by you. Wanted to know why have you used object.readLine() whats the purpose ? can i skip it in my program?

  • HELP!sumit badaya May 24, 2012 at 2:19 PM

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at MiniCalc.main(MiniCalc.java:9) i got this error in my program which is as follows..i dont want to import anything. ___ class MiniCalc { public static void main(String args[]) { int x,y; x=Integer.parseInt (args[0]); y=Integer.parseInt (args[1]); int a=Integer.parseInt (args[2]); switch (a) { case 1: System.out.println("Enter the number one=" +(x+y)); break; case 2: System.out.println("Enter the number one=" +(x-y)); break; case 3: System.out.println("Enter the number one=" +(x*y)); break; case 4: System.out.println("Enter the number one=" +(x/y)); break; default: System.out.println("Invalid Entry!"); } } } _____

  • java progrm errorRaza ullah burki June 30, 2012 at 11:09 AM

    import javac.swing.*: class TestSwitch { public static void main(String str[]) { int a,b,c; char ch,s; s=JOptionPane.ShowInputDialog("enter first value"); a=Integer.parseInt(s); s=JOptionPaneshowInputDialog("enter second value"); b=Integer.parseInt(s); ch=JOptionPane.showInputDialog("enter a symbol"); switch(ch) { case"+"; c=a+b; JOptionPane.showInputDialog(null,"addition="+c); break; case"-" c=a-b; JOptionPane.showInputDialog(null,"subtraction="+c); break; case"*"; c=a*b; JOptionPane.showInputDialog(null,"addition="+c); default: JOptionPane.showInputDialog(null,"invalud operator="+c); } System.exit(0); } }

  • Java Program ExamplesMatib Nicole August 4, 2012 at 4:26 AM

    Very Helpful Example is the best way to teach.

  • For java programHitesh Khatri December 17, 2012 at 12:59 AM

    import.java.io.*; class NoOfDays { public static void main(String args[]) { Console con = System.console(); int month, year, numdays = 0; //int month = 2; //int year = 2000; //int numdays = 0; System.out.println("Enter the month"); month = Integer.parseInt(con.readLine()); System.out.println("Enter the year"); year = Integer.parseInt(con.readLine()); switch(month) { case 0: case 1: case 4: case 6: case 7: case 9: case 11: numdays = 31; break; case 3: case 5: case 8: case 10: numdays = 30; break; case 2: if( ((year % 4 == 0 ) && !(year % 100 ==0)) || (year %400 == 0) ) numdays = 29; else numdays = 28; break; default: System.out.println("Invalid Month"); } System.out.println("Number od days" +numdays); } } this program is giving a error identifier Expected in line 1(import.java.io.*;) Please help me :(

  • computernampalamary September 12, 2012 at 2:25 PM

    good views

  • javasnehal September 21, 2012 at 9:56 AM

    good site for lerners

  • Given Examplebiloy October 10, 2012 at 1:58 PM

    The code has error.

  • javabala October 28, 2012 at 8:34 AM

    java is my fav sub

  • Java programJimmie Pierre December 3, 2012 at 3:56 AM

    Create a program that gives you the following options for a dental office: 1. Cleaning - $35.00 2. Extractions - $70.00 3. X-rays - $150.00 4. Quit when the user selects an option, display the total cost that falls under that category.

  • Java ProgramNiraj Chaurasia May 1, 2013 at 1:50 PM

    I Like Java Program

  • javaHema July 5, 2013 at 1:58 PM

    Give some more examples.

  • String in switchkiran August 4, 2013 at 11:16 AM

    How we can pass the String in switch case? please help me

  • Comment on SwitchExampleKuldeep Singh October 1, 2013 at 3:24 AM

    Thanks for writing this program. I had a doubt. But now, it is cleared because of this program. http://www.roseindia.net/java/beginners/SwitchExample.shtml

  • javanirjharkundu November 25, 2013 at 8:04 PM

    import java.io.*; import java.util.Scanner; public class swcase1{ public static void main(String[] args) throws Exception{ BufferedReader object = new BufferedReader (new InputStreamReader(System.in)); System.out.println("1. Fibonacci"); System.out.println("2. prime"); System.out.println("enter your choice:"); int a= Integer.parseInt(object.readLine()); switch (a) { case 1: { Scanner input = new Scanner(System.in); System.out.print("Enter a number: "); int entered_num= input.nextInt(); System.out.println("The Fibonacci Sequence of the Number " + entered_num + " is:"); int constant1 = 1; int constant2= 1; int nextNumber = 0; int count=0; for (int i=0;i<=entered_num;i++) { System.out.println("F" + count + "=" + nextNumber); constant1 = constant2; constant2 = nextNumber; nextNumber = constant1 + constant2; count++; } } break; case 2: { int n, status = 1, num = 3; Scanner in = new Scanner(System.in); System.out.println("Enter the number of prime numbers you want"); n = in.nextInt(); if (n >= 1) { System.out.println("First "+n+" prime numbers are :-"); System.out.println(2); } for ( int count = 2 ; count <=n ; ) { for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) { if ( num%j == 0 ) { status = 0; break; } } if ( status != 0 ) { System.out.println(num); count++; } status = 1; num++; } } break; default: System.out.println("Invalid Entry!"); } { System.exit(0); } } }

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Beginners

if else statement in java
if else statement in java  if else statement in java explain with example 

Java Beginners

if else statement in java
if else statement in java  explain about simple if else statement and complex if else statement in java with an example 

Tools For Java Technology

The Switch statement
. 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.... Here is the general form of switch statement: switch (expression){ case 1 

Java Tips and Examples

Switch Statement example in Java
Switch Statement example in Java    ... more about the switch statement in Java. The following java program tells you... for implementing the switch statement. Here, you will learn how to use the switch statement 

Java Beginners

Switch Statement
Switch Statement  How we can use switch case in java program ?   Note:-Switch case provides built-in multiway decision statement.It... switch case statement. The program displays the name of the days according to user 

Java Beginners

GOTO Statement in java
GOTO Statement in java  I have tried many time to use java goto statement but it never works i search from youtube google but e the example on net are also give compile error. if possible please give me some code with example 

JDBC

JDBC Prepared Statement Example
JDBC Prepared Statement Example       Prepared Statement is different from Statement object... Prepared Statement Example. The code include a class JDBC 

Java Tips and Examples

'if' Statement - if inside if
Java Notes'if' Statement - if inside if if inside if You can put an if statement inside another if statement. Example -- series... the condition in an if statement, Java thinks it's finished with the body 

Java Tips and Examples

if Statement - Overview
Java Notesif Statement - Overview Purpose The purpose of the if statement... with if. [The other 1% of the decisions use the switch/case statement... statement to do if condition is false Example 1 - true and false parts 

Java-Tutorials

If statement in java 7
If statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. There are various way to use if statement with else - If Statement :  If statement contains one boolean 

Java Beginners

sontrol statement - Java Beginners
sontrol statement  hi to all, can anybody send me program in which "break" and "continue" is used simultaneously.? plz its urgent.  Hi Friend, You can try the following example code: public class ContinueBreak 

Java-Tutorials

Switch Statement in java 7
Switch Statement in java 7 This tutorial describes the if statement in java 7. This is one kind of decision making statement. Switch Statements... executed. Example : In this example we are using switch -case statement 

Java Beginners

java if statement
java if statement  If statement in Java 

Java Beginners

Continue and break statement
statement in java program?   The continue statement restart the current... is an example of break and continue statement. Example - public class ContinueBreak... is an example of break and continue statement. Example - public class ContinueBreak 

Java Tips and Examples

'if' Statement - Braces
Java Notes'if' Statement - Braces Braces { } not required for one... one statement to do if condition is false Example 1 - true and false... was expected. What is a statement? A statement is a part of a Java 

JDBC-Tutorials

Prepared Statement Example
is used to make the SQL statement execution efficient. In Java, when we use... the PreaparedStatement. In this example we will execute a SQL statement using PreparedStatement object. In this example we will use "INSERT INTO" SQL statement 

JDBC

JDBC Update Statement Example
.style1 { text-align: center; } JDBC Update Statement Example JDBC update statement is used to update the records of a table using java application program. The Statement object returns an int value that indicates how many 

Java Tips and Examples

'while' Statement
Java Notes'while' Statement Purpose - to repeat statements The purpose of the while statement is to repeat a group of Java statements many times. It's written just like an if statement, except that it uses 

Java-Tutorials

Break Statement in java 7
-while, switch statement. Example : This is a simple example of unlabeled break...Break Statement in java 7 In this tutorial we will discuss about break statement in java 7. Break Statement : Java facilitate you to break the flow 

Java Tips and Examples

Java - Break statement in java
Java - Break statement in java     ... statement is used in many programming languages such as c, c++, java etc. Some... statement is used in while loop, do - while loop, for loop and also used in the switch 

General

Java Import Statement Cleanup - Java Tutorials
Java Import Statement Cleanup 2002-06-18 The Java Specialists' Newsletter [Issue 051] - Java Import Statement Cleanup Author: Dr. Cay S. Horstmann... to receive training in Design Patterns. Java Import Statement Cleanup 

Java Tips and Examples

Java - Continue statement in Java
Java - Continue statement in Java       Continue: The continue statement is used in many programming languages such as C, C++, java etc. Sometimes we do not need to execute some 

Java-Tutorials

Continue Statement in java 7
Continue Statement in java 7 In this tutorial we will discuss about continue statement in java 7. Continue Statement : Sometimes you need to skip block... statement in loops. In java 7, Continue statement stops the current iteration 

Java Tips and Examples

Continue statement in java
Continue statement in java In this section we will discuss about continue statement in java. continue is one of the branching statement used in most... statement. Example : Unlabeled continue statement for(i=0;i<5;i++) { for(j 

JDBC

JDBC Batch Process With Prepare Statement Example
JDBC Batch Process With Prepare Statement Example: In this example, you can learn about jdbc batch process with prepare statement. First of all, we will create a java class BatchProcessWithPrepareStatement.java class that import 

JSP-Tutorials

JSP IF Statement
in the core Java programming. Additionally, in JSP the conditional if statement... and/or as the IF-ELSE statement and/or IF-ELSE ladder statement. In Java we can use...JSP IF Statement In this section we will read about how the If statement 

JDBC

JDBC Prepared statement Close
an example from JDBC Prepared Statement Close. In this program, the code describe how... JDBC Prepared statement Close       The Prepared statement interface extends from statement 

General

Java Break Statement
Java Break Statement      ... of java. It is used to terminate the loop coded inside the program.  Example below demonstrates the working of break statement inside the program. This example 

Core Java

Break statement in java
Break statement in java Break statement in java is used to change the normal control flow of  compound statement like while, do-while , for. Break... is also used in switch case. Break statement allow a force termination of  

JDBC

JDBC Batch SQL Update Statement Example With Return Number of Effected Rows
JDBC Batch SQL Update Statement Example With Return Number of Effected Rows: In this example, we are discuss about update statement with return number... on the statement and returns an array of integers, and each element of the array 

DMCA.com