+ 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:"); } }

30th Nov 2021, 7:31 AM
Mirasol Sontousidad
Mirasol Sontousidad - avatar
15 ответов
+ 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") ; } }
30th Nov 2021, 10:48 AM
Jayakrishna 🇮🇳
+ 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?
30th Nov 2021, 7:50 AM
Jayakrishna 🇮🇳
+ 1
The should be display the name of items, price, and the total amount of grocery item
30th Nov 2021, 7:57 AM
Mirasol Sontousidad
Mirasol Sontousidad - avatar
+ 1
The output should be be display the name of items, price, and the total amount of grocery item
30th Nov 2021, 7:58 AM
Mirasol Sontousidad
Mirasol Sontousidad - avatar
+ 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
30th Nov 2021, 10:16 AM
Mirasol Sontousidad
Mirasol Sontousidad - avatar
+ 1
My post has suggestions to implement correct code .. Read again.. Try those.. If you not understand any then reply for that specific details...
30th Nov 2021, 10:28 AM
Jayakrishna 🇮🇳
+ 1
Ash(Back In Original Form) "Like a JVM" what it means?
30th Nov 2021, 3:46 PM
Jayakrishna 🇮🇳
+ 1
Hi I know nothing about coding , please anyone explain
2nd Dec 2021, 5:07 AM
Saswat Nayak IX E
0
Can anyone help me
30th Nov 2021, 7:31 AM
Mirasol Sontousidad
Mirasol Sontousidad - avatar
0
Tap Try it yourself to see the whole program in action.
1st Dec 2021, 11:44 PM
Abdalaziz Alkaml
- 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:"); } }
2nd Dec 2021, 6:30 AM
Mustafa Abass
- 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..
30th Nov 2021, 8:21 AM
Jayakrishna 🇮🇳