Wednesday 24 January 2018

Do While in java

import javax.swing.JOptionPane;

public class DoTest
  // start attributes
  // end attributes
{
  // start methods
  public static void main(String[] args)
  {
   
    int num;
   
    do
    {
     
      String s1 = JOptionPane.showInputDialog("Enter your choice, 0 to end");
      num = Integer.parseInt(s1);
     
      if(num==1)
      System.out.println("chocolate selected");
      else
      if(num==2)
      System.out.println("Candy selected");
      else
      System.out.println("peanuts default choice");
    }
    while(num > 0);
  }
  // end methods
}

0 comments: