Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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.
- Example: Enter a number: 3.2
- 3.2 2.7 2.2 1.7 1.2 0.7 0.2
- */
- import java.util.Scanner;
- public class WhileLoop1{
- public static void main(String[] args){
- Scanner kb = new Scanner(System.in);
- System.out.print("Enter a number: ");
- double xValue = kb.nextDouble();
- while( xValue > 0 ){
- System.out.print(xValue + " ");
- xValue -= 0.5;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement