Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Benneth Paredis
4,597 Pointsplease help me with my multiplication program
import java.io.Console;
public class calculator { public static void main(String[] args) { Console console = System.console(); String numberA = console.readLine("type a number: "); String numberB = console.readLine("type a number you want to multiply it with: "); int number1 = Integer.parseInt("numberA"); int number2 = Integer.parseInt("numberB"); int answer = (number1 * number2); //i dont know what to do on this line its so confusing
} }
1 Answer
Derek Markman
16,291 PointsIt's when you're passing in your argument for the parseInt() method. Don't use quotation marks. You would only use quotation marks if you were passing in a string literal like:
import java.io.Console;
public class calculator {
public static int number1;
public static int number2;
public static int answer;
static Console console = System.console();
public static void main(String[] args) {
//It's also worth noting that doing it this way is redundant,
//because there is no need to parse to an int,
//you could just assign number1 and number2 to a '5'.
//Then print out the answer after you do some sort of operation on the two int variables.
number1 = Integer.parseInt("5"); //String literal passed in
number2 = Integer.parseInt("5"); //String literal passed in
answer = (number1 * number2);
System.out.println(answer);
}
}
Otherwise you just type the variable directly inside like:
import java.io.Console;
public class calculator {
public static int number1;
public static int number2;
public static String numA;
public static String numB;
public static int answer;
static Console console = System.console();
public static void main(String[] args) {
numA = console.readLine("type a number: ");
numB = console.readLine("type a number you want to multiply it with: ");
number1 = Integer.parseInt(numA); //String variable passed in
number2 = Integer.parseInt(numB); //String variable passed in
answer = (number1 * number2);
System.out.println(answer);
}
}
Let me know if you have any other questions.