http://pastebin.com/aLnCZ5Rv Can anyone take a look at that code and tell me why
ID: 3584479 • Letter: H
Question
http://pastebin.com/aLnCZ5Rv
Can anyone take a look at that code and tell me why it doesn't make a table like this when run:
number square cube
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
It just says build successful but no table comes up.
I only want help to fix my existing code. I DO NOT want some code copy pasted from another site, I already got the code, I just want it fixed. I'm new to programming and Java. I will give lifesaver for a fix to my code. Code from other site/no help will get 1 star.
Explanation / Answer
package TableOfSquaresandCubes231;
public class TableOfSquaresAndCubes {
public static void main (String[] args ) {
// it is fixed i removed two braces here
// just print new line after each statemtn now it s working fine.
int n;
System.out.print("Number" + "Square" + "Cube");
n=0;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=1;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=2;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=3;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=4;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=5;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=6;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=7;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=8;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=9;
System.out.printf(n + " " +n*n + "" + n*n*n);
n=10;
System.out.printf(n + " " +n*n + "" + n*n*n);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.