Respuesta :
Answer:
The Java code is given below
Explanation:
// SquaresCubes.java
import java.util.Scanner;
public class SquaresCubes {
public static void main(String args[]) {
int srart, end;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
// Getting the input entered by the user
System.out.print("Starting number :");
srart = sc.nextInt();
System.out.print("Ending number :");
end = sc.nextInt();
System.out.println("============\t============\t============");
System.out.println(padString("Number",12)+""+padString("Squared",16)+""+padString("Cubed",16));
System.out.println("============\t============\t============");
printSquaresCubes(srart, end);
System.out.println("============\t============\t============");
}
private static void printSquaresCubes(int srart, int end) {
for (int i = srart; i <= end; i++) {
System.out.printf("%12d\t%12d\t%12d\n", i, i * i, i * i * i);
}
}
private static String padString(String s, int num) {
int len = s.length();
if (num <= len) {
return s;
}
for (int i = 0; i < (num - len); i++) {
s = " " + s;
}
return s;
}
}
============================
Output:
Starting number :5
Ending number :10
============ ============ ============
Number Squared Cubed
============ ============ ============
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
============ ============ ============
========================
Output#2:
Starting number :100
Ending number :110
============ ============ ============
Number Squared Cubed
============ ============ ============
100 10000 1000000
101 10201 1030301
102 10404 1061208
103 10609 1092727
104 10816 1124864
105 11025 1157625
106 11236 1191016
107 11449 1225043
108 11664 1259712
109 11881 1295029
110 12100 1331000
============ ============ ============