Using a while loop create a program that will prompts the user for two numbers and then print out a list of all the numbers between the given numbers (inclusive) squared.
Sample Run1
Enter two numbers: 4 8
Output1: List = 16 25 36 49 64
Sample Run2
Enter two numbers: -2 -6
Output2: List = 36 25 16 9 4
import java.util.Scanner;
public class Square {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.in.print("Enter teo numbers: ");
int a = scanner.nextInt();
int b = scanner.nextInt();
for (int i = Math.min(a, b); i <= Math.max(a, b); i++) {
cout << i * i << " ";
}
}
}
Comments
Leave a comment