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
14 odpowiedzi
+ 3
What is your attempt?
+ 1
Could you calculate it by writing in an algebra form on a paper first?
+ 1
Giving user input of integer datatype
0
I can't count the total number of pies
0
Hmm, didn't think about it, thanks!
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
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.
0
How can I use Fruit variable?
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.
0
thanks you
0
What is this code for?
int a=sc.nextInt();
0
Thank you so much
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. ::)