Answer:
Step-by-step explanation:
The following code is written in Java and takes the calories and fat grams, then turns the fat grams into calories and adds them to the rest of the calories. Then it calculates the percentage of fat grams in the food item by dividing the fat gram calories by the total amount of calories in the food item. Finally, it prints out the exact percentage result.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter number of Calories");
double calories = Integer.parseInt(in.nextLine());
System.out.println("Enter number of Fat");
double fat = Integer.parseInt(in.nextLine());
double totalCalories = (fat*9) + calories;
double fatPercentage = (fat*9) / totalCalories;
System.out.println("Percentage of Fat: " + fatPercentage + "%");
}