Results 1 to 3 of 3
  1. #1
    antidup is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default How to loop this CODE using do while

    Java Code:
    import javax.swing.*; 
    public class switchmove {
        
        public static void main(String[] args) {
    	String wen = JOptionPane.showInputDialog(null, "Input your desire channel:", "Select", JOptionPane.PLAIN_MESSAGE);
    	int w=Integer.parseInt(wen);
    
        	switch (w) {
      case 2:
        JOptionPane.showMessageDialog(null, "ABS-CBN", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;
      case 5:
        JOptionPane.showMessageDialog(null, "RPN", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;
      case 9:
        JOptionPane.showMessageDialog(null, "CS 9 TV", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;
      case 12:
        JOptionPane.showMessageDialog(null, "GMA", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;
      case 20:
        JOptionPane.showMessageDialog(null, "IBC", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;
      case 21:
        JOptionPane.showMessageDialog(null, "TV 5", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;
      case 23:
        JOptionPane.showMessageDialog(null, "Studio 23", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;
      case 39:
        JOptionPane.showMessageDialog(null, "COC tv", "Result", JOptionPane.INFORMATION_MESSAGE);
        break;   
      default:
        JOptionPane.showMessageDialog(null, "WALA mani nga CHANNEL", "Result", JOptionPane.ERROR_MESSAGE);
        break;
    }
        }
    }
    Last edited by JosAH; 08-26-2011 at 12:21 PM. Reason: added [code] ... [/code] tags

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Also posted with the title "How to loop this CODE using For loop".

    -----

    Read through Control Flow Statements in Oracle's Tutorial. It may solve your problem or it may help you to ask a question. If you ask a question a couple of things to keep in mind are that people will want to see your attempt, or a specific statement from the Tutorial or elsewhere that you would like to have explained. And when posting code there is no reason for it to include a lot of "clutter" like the message dialogs and their associated messages which really have nothing to do with loops.

  3. #3
    peterhabe is offline Member
    Join Date
    Jul 2010
    Posts
    43
    Rep Power
    0

    Default

    You could just use a while loop like this:

    while(true){
    //all the code in your main method here

    String playAgain = JOptionPane.showInputDialog(null, "Do you want to run this code again?", " ", JOptionPane.PLAIN_MESSAGE);

    if(playAgain.equalsIgnoreCase("no"))
    break;

    }

Similar Threads

  1. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 06:46 PM
  2. Replies: 7
    Last Post: 11-22-2010, 03:38 PM
  3. Why isn't this while loop code working
    By GreenTea in forum New To Java
    Replies: 16
    Last Post: 11-10-2010, 04:14 AM
  4. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 09:46 PM
  5. while loop skips code
    By ejs7597 in forum New To Java
    Replies: 3
    Last Post: 02-28-2009, 04:07 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
  •