0

I can't solve the problem

I recently started learning Java and I can't solve one problem: You have a bowl on your counter with an even number of pieces of fruit in it. Half of them are bananas, and the other half are apples. You need 3 apples to make a pie. Task Your task is to evaluate the total number of pies that you can make with the apples that are in your bowl given to total amount of fruit in the bowl. Input Format An integer that represents the total amount of fruit in the bowl. Output Format An integer representing the total number of whole apple pies that you can make. Sample Input 26 Sample Output 4

16th Aug 2022, 5:36 PM
Akridem
Akridem - avatar
14 Answers
+ 3
What is your attempt?
16th Aug 2022, 5:53 PM
Justice
Justice - avatar
+ 1
Could you calculate it by writing in an algebra form on a paper first?
16th Aug 2022, 6:21 PM
abpatrick catkilltsoi
abpatrick catkilltsoi - avatar
18th Aug 2022, 6:36 AM
Kailash Yandrapu
+ 1
Giving user input of integer datatype
18th Aug 2022, 6:43 AM
Kailash Yandrapu
0
I can't count the total number of pies
16th Aug 2022, 5:58 PM
Akridem
Akridem - avatar
0
Hmm, didn't think about it, thanks!
16th Aug 2022, 6:25 PM
Akridem
Akridem - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int fruit = input.nextInt(); int x = 26; int y = 13; int c = 2; System.out.println(x/y); System.out.println(x-y*c); } } I get two answers at once in one test, what did I do wrong
17th Aug 2022, 12:21 PM
Akridem
Akridem - avatar
0
First, you define a variable called fruit but have never used it. Second, both of your equations is not relate to the question, it should be (fruit/2)/3. Third, you have double println statements, so having two outputs is normal. PS. you may use floor division (//) to make it simpler as you cannot make sth called partial pie.
17th Aug 2022, 12:29 PM
abpatrick catkilltsoi
abpatrick catkilltsoi - avatar
0
How can I use Fruit variable?
17th Aug 2022, 4:09 PM
Akridem
Akridem - avatar
0
System.out.println(fruit/2) Like this. I need to correct that // floor division only available in Python, in Java you need to use Math.floorDiv(). If you even don't know how to use the declare variable, please revise the lessons and exercise first.
17th Aug 2022, 4:18 PM
abpatrick catkilltsoi
abpatrick catkilltsoi - avatar
0
thanks you
17th Aug 2022, 4:45 PM
Akridem
Akridem - avatar
0
What is this code for? int a=sc.nextInt();
18th Aug 2022, 6:42 AM
Akridem
Akridem - avatar
0
Thank you so much
18th Aug 2022, 7:03 AM
Akridem
Akridem - avatar
0
Hello, I am learning Java today and I can't change the code in Java to complete the quiz linked to Increments. Any suggestions? Nevermind, I figured it out. Did you turn it off and turn it on again? Yes, Yes I did. That fixed my problem. Thank you, IT Crowd. ::)
18th Aug 2022, 1:29 PM
Jason