Advertisement
fosterbl

WhileLoop2.java

Oct 8th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. /*
  2. Prompt the user and receive input for a int number n. Repeatedly print the square root (Math.sqrt) of all the numbers from 1 up to and including n.
  3. Example: Enter a number: 5
  4.         1.0 1.41421356237 1.73205080757 2.0 2.2360679775
  5. */
  6. import java.util.Scanner;
  7.  
  8. public class WhileLoop2{
  9.    public static void main(String[] args){
  10.       Scanner kb = new Scanner(System.in);
  11.       System.out.print("Enter a number: ");
  12.       int n = kb.nextInt();
  13.       int countUp = 1;
  14.       while( countUp <= n ){
  15.          System.out.print(Math.sqrt(countUp) + " ");
  16.          countUp++;
  17.       }
  18.    }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement