Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String cubos(int n) {
- String res = "";
- int suma = 0;
- int ultimoPrimo = 0; // para 2u + 1
- for (int i = 1; i <= n; i++) {
- res += i + "^3 = ";
- for (int j = 1; j <= i; j++) {
- res += (2 * ultimoPrimo + 1) + " ";
- if (j == i) {
- res += "= ";
- }
- else res += "+ ";
- suma += 2 * ultimoPrimo + 1;
- ultimoPrimo++;
- }
- res += suma + "\n";
- suma = 0;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment