Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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.
- Example: Enter a number: 5
- 1.0 1.41421356237 1.73205080757 2.0 2.2360679775
- */
- import java.util.Scanner;
- public class WhileLoop2{
- public static void main(String[] args){
- Scanner kb = new Scanner(System.in);
- System.out.print("Enter a number: ");
- int n = kb.nextInt();
- int countUp = 1;
- while( countUp <= n ){
- System.out.print(Math.sqrt(countUp) + " ");
- countUp++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement