Exercise 8 Java


#1

Hi all,

Excited to start my journey on codeacademy, I can't believe I am stuck already though!!

"1. Set the int variable myNumber equal to the product of two numbers."

This shouldn't be too hard, however I think I am lost either in the english (shouldn't be the case) or I've just forgotten something from previous exercises. How do I go about doing this correctly?

Here is my code. Sorry I can't figure out how to even format it correctly.

public class Arithmetic {
public static void main(String[] args) {

	int myNumber =  
	System.out.println(myNumber);

}

}


#2

I've now solved this. I didn't know that you'd get the answer after a few times of failure. Turns out I was just missing the semicolon at the end!


#3

Please check my code:

public class Arithmetic {
public static void main(String[] args) {

	int myNumber = 
	System.out.println(int myNumber;

}

}

These are the errors I have received:
Arithmetic.java:5: error: '.class' expected
System.out.println(int myNumber;
^
1 error (the ^ should be under 'm')


#4

You need to finish that line. Here is the task:

Set the int variable myNumber equal to the product of two numbers.

Are you unsure about what product means?


#5

take a look at this

public class Arithmetic {
	public static void main(String[] args) {

		int myNumber = 4; //You have to store something here

		//we have declared myNumber already and stored 4 in it 
		//(there is no need for the int keyword when we are using myNumber)
		//in other words we have reserves a block of memory
		//and labeled it myNumber and in that block we put the value
		//4(we also said that in this block only objects of type int can be stored in it)
		//So whenever we use myNumber anywhere in our code it refers to the number 4

		System.out.println(myNumber);//You also needed to close this bracket
	}
}

#6

Thank you so much. Your answer helped me a lot


#7

If I am correct, product means "2 or more numbers multiplied to create the answer (product)"


#8

Yes, that's it exactly.


#9

Also, to be honest I was focused on doing: System.out.println(myNumber);

Maybe that was the problem


#10

I find that too, I like to get right to doing stuff and don't read all the instruction until it starts throwing errors at me :wink:


#11

So how should I complete it? Do I do:

"int myNumber = 4;"

without the quotation marks of course.


#12

This is what it looks like:


#13

I would pick two numbers that I liked :smile: , and then use the symbol for multiplication to multiply them together, so something like:

int myNumber = 33 * 11;


#14

Oh thank you! I think I'm going to need a Programming for Dummies guide haha.


#15

Once you get to the end -- go back to the beginning and Reset the course. You will be surprised how much clearer things will be.


#16

Thanks for the advice. Happy coding!


#17

@albionsrefuge is right @gabygirl01. We have all been at this stage. You will understand it in time


#18

Can someone help me, as I do follow above tips but I am still unable to get it right? Plz :(


#19

remove the int declaration from the println statement. Your declaration makes no sense to the interpreter.


#20

@microslayer68337 in regards to the what i posted in this thread earlier, since you have already declared myNumber on line 4 and stated it is of type int all you have to do is pass the variable name myNumber on line 5 without the int keyword