rsvaco

CCDII4ai

Dec 20th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. public static String cubos(int n) {
  2.     String res = "";  
  3.     int suma = 0;
  4.     int ultimoPrimo = 0; // para 2u + 1
  5.     for (int i = 1; i <= n; i++) {
  6.         res += i + "^3 = ";
  7.         for (int j = 1; j <= i; j++) {
  8.             res += (2 * ultimoPrimo + 1) + " ";
  9.             if (j == i) {
  10.                 res += "= ";
  11.             }
  12.             else res += "+ ";
  13.             suma += 2 * ultimoPrimo + 1;
  14.             ultimoPrimo++;
  15.         }
  16.         res += suma + "\n";
  17.         suma = 0;
  18.     }
  19.     return res;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment