Answer to Question #254082 in Java | JSP | JSF for guru

Question #254082

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

1
Expert's answer
2021-10-20T07:39:07-0400
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 << " ";
    }
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS