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.
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.
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");
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!");
}
}
}
_____
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 :(
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
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
IT 114('COMPUTER PROGRAMMING')irene September 14, 2011 at 1:26 PM
i wnat to learn more and explore,about programs & codes,but i cant,how?/hahaha
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.
hi i want to know more about you... wasim akram March 23, 2012 at 1:08 AM
nice website, i read the topics from this site in exams.. very good job thanks..
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); } }
what is denoted by if there is ==> switch (x%7)wath July 11, 2012 at 10:33 AM
i'd be v thankful to your answer
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
Post your Comment