Count amount of times displayed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Count amount of times displayed

How do i make this program to be able to count the amount of time that a word is shown and multiply that number with the money for next try, then add that current total to the total amount. Example: Enter your total amount for betting: $200 Enter amount for your next try: $20 2 2 4 Plums Plums Melons So, i want the program to now say: Plums appeared 2 times. 2 X 20 = 40 40 + 200 = 240 https://code.sololearn.com/c6c0zv87dDEL/?ref=app

14th Jan 2022, 8:04 PM
Bobby Dike
Bobby Dike - avatar
1 Answer
+ 1
You could make an array of the fruits the user got, then loop through the array, and if there is a copy just increase the count variable. So it would roughly look like this: int numOfPlums = 0; for (int x = 0; x < array.length; x++ ){ if (array[x].equals("Plums")) { numOfPlums++; } } Then just multiply numOfPlums by money. You can also do this with every fruit type. So if you get a count of all fruits you can then get the fruit with the highest appearance in the array.
14th Jan 2022, 8:36 PM
Isaac Nelson
Isaac Nelson - avatar