How do I use printf to round to tenths for this code? { public static void main(String[] args) { double cups; double ounces; //Create Scanner Scanner input = new Scanner(System.in); //ask and receive users 1st ingredient { System.out.print("Enter the first ingredient: "); String firstIngredient = input.nextLine(); } //ask and receive users 2nd ingredient { System.out.print("Enter the second ingredient: "); String secondIngredient = input.nextLine(); } //ask and receive users 3rd ingredient { System.out.print("Enter the third ingredient: "); String thirdIngredient = input.nextLine(); } //Ask user for amount of cups of ingredient 1 { System.out.print("Enter the number of cups for the first ingredient: "); double cup1 = input.nextDouble(); } //Ask user for amount of cups of ingredient 2 { System.out.print("Enter the number of cups for the second ingredient: "); double cup2 = input.nextDouble(); } //Ask user for amount of cups of ingredient 3 { System.out.print("Enter the number of cups for the third ingredient: "); double cup3 = input.nextDouble(); } { double totalCups = cup1+cup2+cup3; } { double answer = totalCups*8; } { System.out.println("The recipe uses " + firstIngredient + ", " + secondIngredient + ", and " + thirdIngredient ); } { //System.out.printf( "%.1f" + answer) ; ?? } } }
How do I use printf to round to tenths for this code?
{
public static void main(String[] args)
{
double cups;
double ounces;
//Create Scanner
Scanner input = new Scanner(System.in);
//ask and receive users 1st ingredient
{
System.out.print("Enter the first ingredient: ");
String firstIngredient = input.nextLine();
}
//ask and receive users 2nd ingredient
{
System.out.print("Enter the second ingredient: ");
String secondIngredient = input.nextLine();
}
//ask and receive users 3rd ingredient
{
System.out.print("Enter the third ingredient: ");
String thirdIngredient = input.nextLine();
}
//Ask user for amount of cups of ingredient 1
{
System.out.print("Enter the number of cups for the first ingredient: ");
double cup1 = input.nextDouble();
}
//Ask user for amount of cups of ingredient 2
{
System.out.print("Enter the number of cups for the second ingredient: ");
double cup2 = input.nextDouble();
}
//Ask user for amount of cups of ingredient 3
{
System.out.print("Enter the number of cups for the third ingredient: ");
double cup3 = input.nextDouble();
}
{
double totalCups = cup1+cup2+cup3;
}
{
double answer = totalCups*8;
}
{
System.out.println("The recipe uses " + firstIngredient + ", " + secondIngredient + ", and " + thirdIngredient );
}
{
//System.out.printf( "%.1f" + answer) ; ??
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images