public class MathPractice{
public static void main(String args){
// TO DO:
// 1. Declare and initialize two variables of type int.
int x;
int y;
x=5;
y=6;
// 2. Declare and initialize a variable to hold the sum of the two variables you created.
sum=x+y;
// 3. Declare and initialize a variable to hold the difference of the two variables you created.
diff=x+y;
// 4. Declare and initialize a variable to hold the product of the two variables you created.
pro=x+y;
// 5. Print the sum, difference, and product to the console.
System.out.Println(sum,diff,pro);
}
}
Hi Kevin,
I took a look at this code snippet and I think I see what could be the problem- on steps 2,3,4 the variables must be declared with a type since those are the first times those variables are appearing in your program.
Try changing those steps to what I have here, I bolded the new parts:
// 2. Declare and initialize a variable to hold the sum of the two variables you created.
int sum=x+y;
// 3. Declare and initialize a variable to hold the difference of the two variables you created.
int diff=x-y;
// 4. Declare and initialize a variable to hold the product of the two variables you created.
int pro=x*y;
Then, in step 5’s print statement, the p in println must be lowercase. Also, the part you put into the println statement won’t understand the commas how you have them. You could just do separate print statements for each like:
System.out.println(sum);
System.out.println(diff);
System.out.println(pro);
I hope this helps! Sometimes fixing one issue brings about a new one, but this will hopefully get you closer
Lindsay
1 Like
Lindsay,
Thank you so much and for the quick response. I taught AP CSP and know my basics well, but as you know it is a little frustrating when you try to debugg and you can’t get the code to compile correctly. I will keep you in my contacts (forum) and I am sure you will hear from me again
Have a wonderful day!
Kevin
| lindsay.davis Code.org CSA & CS Principles facilitator
June 14 |
Hi Kevin,
I took a look at this code snippet and I think I see what could be the problem- on steps 2,3,4 the variables must be declared with a type since those are the first times those variables are appearing in your program.
Try changing those steps to what I have here, I bolded the new parts:
// 2. Declare and initialize a variable to hold the sum of the two variables you created.
int sum=x+y;
// 3. Declare and initialize a variable to hold the difference of the two variables you created.
int diff=x-y;
// 4. Declare and initialize a variable to hold the product of the two variables you created.
int pro=x*y;
Then, in step 5’s print statement, the p in println must be lowercase. Also, the part you put into the println statement won’t understand the commas how you have them. You could just do separate print statements for each like:
System.out.println(sum);
System.out.println(diff);
System.out.println(pro);
I hope this helps! Sometimes fixing one issue brings about a new one, but this will hopefully get you closer
Lindsay
1 Like
You re awesome and your team! I am sure I will have more coming your way this summer as I work through the program…
Kevin, SVT
1 Like
Lindsay,
Really weird, but I tried to access resources, such as google files just like I did last year using the same credentials for code.org and I have a school gmail address and I can’t get access to any of the files.
Can’t make a copy either. I am confused. My code.org log in is not a google address, but that has not changed since 5 years ago.
Can you help me or direct me towards somebody, please.
Thanks.
Kevin
| lindsay.davis Code.org CSA & CS Principles facilitator
June 14 |
Hi Kevin,
I took a look at this code snippet and I think I see what could be the problem- on steps 2,3,4 the variables must be declared with a type since those are the first times those variables are appearing in your program.
Try changing those steps to what I have here, I bolded the new parts:
// 2. Declare and initialize a variable to hold the sum of the two variables you created.
int sum=x+y;
// 3. Declare and initialize a variable to hold the difference of the two variables you created.
int diff=x-y;
// 4. Declare and initialize a variable to hold the product of the two variables you created.
int pro=x*y;
Then, in step 5’s print statement, the p in println must be lowercase. Also, the part you put into the println statement won’t understand the commas how you have them. You could just do separate print statements for each like:
System.out.println(sum);
System.out.println(diff);
System.out.println(pro);
I hope this helps! Sometimes fixing one issue brings about a new one, but this will hopefully get you closer
Lindsay
1 Like