0% found this document useful (0 votes)
5 views1 page

Program B

Uploaded by

akash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Program B

Uploaded by

akash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

PROGRAM B:

import java.util.*;
public class CakeCalculator
{
// works out how many cakes u can make + what’s left
public static int[] cake_calculator(int flour, int sugar)
{
int cakes = Math.min(flour / 100, sugar / 50); // smallest limit decides cakes
int remainingFlour = flour - cakes * 100; // leftover flour
int remainingSugar = sugar - cakes * 50; // leftover sugar
return new int[]{cakes, remainingFlour, remainingSugar};
}

public static void main(String[] args)


{
Scanner sc = new Scanner(System.in);
System.out.print("Enter flour: "); // ask flour
int flour = sc.nextInt();
System.out.print("Enter sugar: "); // ask sugar
int sugar = sc.nextInt();

int[] result = cake_calculator(flour, sugar);


System.out.println("[" + result[0] + ", " + result[1] + ", " + result[2] + "]");
}//end of main
} //end of class

You might also like