Do While Loop

Do While loop Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

35 Comments

  • wat if ud like to get the same statement but instead ask the user to key in the data how would the program be??

  • An easy way would be to use InputStreamReader class and wrap it with BufferedReader class. Then parse the inputted value and set the variable with that value.

    • public class DoWhile {

      public static void main(String[] args) {
      String name = “john”;
      String pswd = “2999”;

      do{
      System.out.println(“Enter the password :” +pswd);
      if(pswd==”2999″){
      System.out.println( “Enter the amount”);
      System.out.println(“draw the money”);
      System.out.println(“withdrawl money”);
      System.out.println(“Reciept”);
      }else
      System.out.println(“Wrong pin number”);
      break;
      }while(name==”john”);

      }

      }

      • • There are total 21 stones. • User will start picking the stones. • User cannot pick more than 3 or remaining stones (whichever is less). • After the user picks the stones, computer does its picking. • Computer cannot pick more than 3 or remaining stones (whichever is less). • Repeat the picking (User and Computer) if stones are available. • Whoever is forced to pick up the last stone loses the game. • Your program should ensure that the computer always wins. ( can u tell me how to solve this problem with this method)

  • Output:
    i and j: 0 10
    i and j: 1 9
    i and j: 2 8
    i and j: 3 7
    i and j: 4 6

    May i know the complete code for this output??plssssss..

    • class code
      {
      public static void main(String[] args)
      {
      int i=0,j=10;
      do{
      System.out.println(“The value of i and j :”+i+ “\t” +j );
      i++;
      j–;
      }while(i<5&&j>5);
      }
      }

  • i want get answer this question plssssss
    write a program that inputs a temperatures in C (celsius ) from the keyboard
    then prints out the corresponding temperature in fahrenheit

    F=C.9/5+32

    • i guess this might be the answer

      import java.io.*;

      public class TempConv

      {

      public static void main(String args[])throws IOException

      {

      BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));

      String str=buf.readLine();

      double temp=Integer.parseInt(str);

      double Farhn=temp*9/5+32;

      System.out.println(“Temperature in Fahrenheit is: “+Farhn);

      }

      }

  • Can someone help me with these?
    Need to find the factorial.
    Input:3

    result:6
    3x2x1=6

    using the do while statement

  • Can i plz have the code for this output i can’t find it.

    output;
    enter a word:
    example

    example
    exampl
    examp
    exam
    exa
    ex
    e
    ex
    exa
    exam
    examp
    exampl
    example

    • public class DoWhile {

      public static void main(String[] args) {

      int i = 1;

      int j = 19;

      do{

      System.out.println(i);

      i++;

      }while(i<10);

      System.out.println(j);

      System.out.println(“Boom!”);

      }

      }

  • may i know the code for this output please….using while looping.
    11111
    11111
    11111
    11111
    11111

  • Make a program that will ask user to enter 10
    numbers. Display only all the even inputs by the user. Use modulo operation in
    this problem. The program must be able to repeat the process if he/she wants to.. paano po to ? yung “must be repeat”? gamit ang do while ? ang alam ko lan g po kasi ay “goto” .. paki sagot naman po salamat..

  • do you know how to get this ? using do and while loop in java?

    Make a program that will ask user to enter 10
    numbers. Display only all the even inputs by the user. Use modulo operation in
    this problem. The program must be able to repeat the process if he/she wants to..

  • please help me with the program.
    The task makes use of the shortcut if statement to count the number of distinctions
    1.1 write a method to count the number of fails using the shortcut if statements. call the method in the test class.
    1.2 change the shortcut if statement to the normal if statements.

  • pls help me,this is my final exam in java and its hard for me to do this,,, i hope somebody could answer my question…how to make a 3 programs with password..note:the password is included in the code not in the dialog box.tnx a lot… i want to know what is the code of this…tnx a lot.

  • Help!!
    I need to create a program where the user inputs height – program asks for if the user wants to input more heights? if yes you program loops back to the start – if not, drops out and gives the average of heights and asks the user if they want to continue or terminate the program???

  • pls I want to get answer to this question very urgent
    do { Happy weekend; } While (y <5); alert(“Good job!”); Var y=5 ;

Sponsors

Facebook Fans