I am trying to compute the total price given the unit price, 17, and the number of items, 20.
public class hw1_task3 {
public static void main(String[] args) {
int total = units * price;
int units = 20;
int price = 17;
System.out.printf("The total is: %d", total);
}
}
What is wrong with the program? I keep getting an error about not being able to find the symbols. I am very new to java, any help is greatly appreciated.
You need to move units and price above total like this:
int price = 17;
int units = 20;
int total = units * price;
You are using the variable before the declaration. These lines
int units = 20;
int price = 17;
should be written first and
int total = units * price;
after that.
So the correct lines will be:
int units = 20;
int price = 17;
int total = units * price;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With