Results 1 to 5 of 5
  1. #1
    Copro is offline Member
    Join Date
    Aug 2009
    Posts
    6
    Rep Power
    0

    Default Need help to solve my problem

    What is the wrong with my program

    need help!


    Java Code:
    import javax.swing.*;
    import java.text.DecimalFormat;
    public class MyMenuCS {
    	public static void main (String[] args) {
    		String ch;
    		int n;
    		int choice;
    		for(n=JOptionPane.showConfirmDialog(null,"Do you want to continue","Really Quit",JOptionPane.YES_NO_OPTION);
    		ch=JOptionPane.showInputDialog(" MENU OF OPERATIONS\n\n"+
    									   " [1] Addition\n" +
    									   " [2] Subtraction\n" +
    									   " [3] Multiplication\n" +
    									   " [4] Division\n" +
    									   " [0] Quit\n\n" +
    									   "Enter your choice: ");
    		choice=Integer.parseInt(ch);     [COLOR="red"][B]<-------')' expected[/B][/COLOR]
    		switch(choice) {
    			case 1:
    				JOptionPane.showMessageDialog(null,"Addition is selected.");
    					String in1,in2;
    					int a,b,sum;
    					in1=JOptionPane.showInputDialog("Enter The First Number:");
    					in2=JOptionPane.showInputDialog("Enter The Second Number:");
    					a=Integer.parseInt(in1);
    					b=Integer.parseInt(in2);
    					sum=a+b;
    					JOptionPane.showMessageDialog(null,"The sum is:"+sum);
    				System.exit(0);
    				break;
    			case 2:
    				JOptionPane.showMessageDialog(null,"Subtraction is selected.");
    				break;
    			case 3:
    				JOptionPane.showMessageDialog(null,"Multiplication is selected.");
    				break;
    			case 4:
    				JOptionPane.showMessageDialog(null,"Division is selected.");
    				break;
    			case 0:
    				break;
    			default:
    				JOptionPane.showMessageDialog(null,"ERROR: Invalid choice.","Error Message",JOptionPane.ERROR_MESSAGE);
    				break;
    			}//switch
    		}//for
    		System.exit(0);       [COLOR="Red"][B] <----------<identifier> expected[/B][/COLOR]
    	}//main
    }//class          [COLOR="red"][B]<----'class' or 'interface' expected[/B][/COLOR]

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Java Code:
    for(n=JOptionPane.showConfirmDialog(null,"Do you want to continue","Really Quit",JOptionPane.YES_NO_OPTION);
    What this line do in your code? Do you know how to define a for loop in correct way? Check the above line of code carefully.

  3. #3
    Copro is offline Member
    Join Date
    Aug 2009
    Posts
    6
    Rep Power
    0

    Default

    Sir Im Just Asking for the correct applying

    for

    plss help

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by Copro View Post
    Sir Im Just Asking for the correct applying
    It's hard to know how to help as this code is completely futzed. I'm afraid that you can't make up methods and your own strange loops and expect them magically to work. If you want to create a for loop, I suggest that you have a look here at the tutorial on them: The for Statement

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Yes, actually your for loop is totally incorrect. So first of all you must correct that. Fubarable send a nice link to you in his post. Then you've to explain your requirement more clearly, if you really need our help. At the same time, keep in mind that you've to put some effort as well.

Similar Threads

  1. Could someone help me to solve this problem...
    By Vinny in forum Java Software
    Replies: 1
    Last Post: 07-08-2009, 06:59 PM
  2. Factory problem: How to Solve it
    By rahul_capricorn in forum Threads and Synchronization
    Replies: 2
    Last Post: 02-11-2009, 04:47 PM
  3. Help me to solve problem
    By mansoorhacker in forum Forum Guides
    Replies: 8
    Last Post: 01-24-2009, 06:29 PM
  4. Solve my Problem
    By kyo in forum New To Java
    Replies: 1
    Last Post: 12-16-2008, 02:22 PM
  5. Help me to solve problem
    By mansoorhacker in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 08:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •