Advertisement
fosterbl

WhileLoop1.java

Oct 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. /*
  2. Prompt the user and receive input for a double variable, xValue. Repeatedly print xValue and then decrease its value by 0.5 as long as xValue remains positive.
  3. Example: Enter a number: 3.2
  4.         3.2 2.7 2.2 1.7 1.2 0.7 0.2
  5. */
  6. import java.util.Scanner;
  7.  
  8. public class WhileLoop1{
  9.    public static void main(String[] args){
  10.       Scanner kb = new Scanner(System.in);
  11.       System.out.print("Enter a number: ");
  12.       double xValue = kb.nextDouble();
  13.      
  14.       while( xValue > 0 ){
  15.          System.out.print(xValue + " ");
  16.          xValue -= 0.5;
  17.       }
  18.    }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement