how is this java program wrong? public class Homework3 { public static void main(String[]args){ for (int i=1;i<=10;i++){ for (int k=1;k<=10;k++);{ System.out.println(i+"x"+j=+(i*j)) } } } } Output should be 1 x 1 = 1 1 x 2 = 2 . . . 1 x 10 = 10 --------------------------- 2 x 1 = 2 2 x 2 = 4 . . . 1 x 10 = 10 --------------------------- . . . 10 x 9 = 90 10 x 10 = 100
For future reference, you can include code in 3 ` (top left of the keyboard, not the single-quote) to get it to highlight like ``` og ``` ``(`) code ``(`) --------------------------------- your code: ``` for (int i=1;i<=10;i++){ //line 1 for (int k=1;k<=10;k++);{ //line 2 System.out.println(i+"x"+j=+(i*j)) //line 3 } } ``` Line 1 looks pretty good. Line 2 has an unexpected semi-colon after the ). A ; symbolizes the end of a statement, and a for loop is a code block, it uses {}, and doesn't end in a ;. You'll get used to it pretty quickly. Line 3 has a couple issues - first, it needs to end in a ;, because it is a statement. Also, in System.out.println(); - you essentially put in a series of variables, and strings ("I am a string"), attached by the + symbol. However, you have a random = sign in there - cleaned up it should look like: ``` System.out.println(i+"x"+j+"="+(i*j)); //line 3 ```
Oh and you use variables i and k in the for loops.. so substitute 'j' for 'k'
There is no semi colon at the end of println statement.
Here's a hello world program to help you guys out: https://docs.oracle.com/javase/tutorial/getStarted/application/
Join our real-time social learning platform and learn together with your friends!