+ 2
What's wrong with this code????
class GroceryItem { public static void main(String[] args) { display String, name,price,total amount ; System.out.println("Enter 5 names of item and prices: "); ("milk",20); ("butter",50); ("eggs",189); ("bread",100); ("tuna",130); int i = 0; while (i < 5) { prices[i] = in.nextDouble(); i++; } double total = 0.00; for (double amount : prices) { total += amount; } System.out.printf("("Enter 5 names of item and prices:"); } }
12 Antworten
+ 6
import java.util.Scanner;
class GroceryItem {
public static void main(String[] args) {
System.out.println("Item: price\n=========== ");
System.out.println("milk : 20 \nbutter : 50 \neggs : 189 \nbread : 100 \ntuna : 100\n");
double[] prices = new double[5];
Scanner in = new Scanner(System.in);
int i = 0;
while (i < 5) {
prices[i] = in.nextDouble();
i++;
}
double total = 0.0;
for(double amount : prices)
total += amount;
for (double amount : prices)
System.out.println(amount);
System.out.println("\n"+total+" is Total price") ;
}
}
+ 3
What are these statements in your program?
It's no meaning and invalid ..
1)
display String, name,price,total amount ;
2)
("milk",20);
("butter",50);
("eggs",189);
("bread",100);
("tuna",130);
? what are you trying with these there?
+ 1
The should be display the name of items, price, and the total amount of grocery item
+ 1
The output should be be display the name of items, price, and the total amount of grocery item
+ 1
import java.util.Scanner;
class GroceryItem
{
public static void main(String[] args) {
display String, name,price,total amount ;
System.out.println("Enter 5 names of item and prices: ");
System.out.println("Item: price\n=========== ") ;
System.out.println("milk : 20 "+"\n"+
"butter : 50" +"\n"+
"eggs : 189 \n"+
"bread : 100"+"\n"+
"tuna : 100");
for (double amount : prices)
System.out.println(amount) ;
System.out.println("Total price : " + total) ;
Before these, initialize price[] array and "in" object as
double[] price = new double[5];
Scanner in = new Scanner(System.in);
}
}
Error again
+ 1
My post has suggestions to implement correct code .. Read again..
Try those.. If you not understand any then reply for that specific details...
+ 1
Ash(Back In Original Form)
"Like a JVM" what it means?
+ 1
Hi I know nothing about coding , please anyone explain
0
Can anyone help me
0
Tap Try it yourself to see the whole program in action.
- 1
What's wrong with this code????
class GroceryItem
{
public static void main(String[] args) {
display String, name,price,total amount ;
System.out.println("Enter 5 names of item and prices: ");
("milk",20);
("butter",50);
("eggs",189);
("bread",100);
("tuna",130);
int i = 0;
while (i < 5) {
prices[i] = in.nextDouble();
i++;
}
double total = 0.00;
for (double amount : prices) {
total += amount;
}
System.out.printf("("Enter 5 names of item and prices:");
}
}
- 2
1) Is it menu of items with price?
solution:
System.out.println("Item: price\n=========== ") ;
System.out.println("milk : 20 "+"\n"+
"butter : 50" +"\n"+
"eggs : 189 \n"+
"bread : 100"+"\n"+
"tuna : 100");
2) May you trying to display prices and total ?
solution:
for (double amount : prices)
System.out.println(amount) ;
System.out.println("Total price : " + total) ;
Before these, initialize price[] array and "in" object as
double[] price = new double[5];
Scanner in = new Scanner(System.in);
Mirasol Sontousidad
And import scanner as:
import java.util.Scanner;
'Name of the items', you are not taking any input for this..!
try all these..
and reply with code if anything going wrong..!
hope it helps..