Respuesta :
Answer:
// package
import java.util.*;
// class definition
class Main
{
//main method of the class
public static void main (String[] args) throws java.lang.Exception
{
try{
// variables
final int q_in_gallon = 4;
int no_of_q;
int no_of_g;
int q_need;
// object to read input
Scanner kb = new Scanner(System.in);
System.out.print("Enter quarts needed: ");
// read the number of quarts
no_of_q = kb.nextInt();
// find number of gallons
no_of_g = no_of_q / q_in_gallon;
// rest of quarts
q_need = no_of_q % q_in_gallon;
// print the result
System.out.println("A job that needs " + no_of_q + " quarts requires " + no_of_g +" gallons plus " + q_need + " quarts.");
}catch(Exception ex){
return;}
}
}
Explanation:
Declare and initialize a variable q_in_gallon with 4.Then read the quarts needed from user.Find the number of gallons by dividing quarts with q_in_gallon.Then find the rest of quarts.Print them into new line.a
Output:
Enter quarts needed: 18
A job that needs 18 quarts requires 4 gallons plus 2 quarts.
Answer: Output if the number of jobs per painting job is 18.
Ans: The painting job of 18 quarts requires 4 gallons and 2 quarts of paint.
Explanation:
import java.util.*;
public class QuartsToGallons {
public static void main(String[] args) {
//Fixed number of quarts
final int numberOfQuarts= 4;
//declare the number of jobs
int numberOfJobs;
//create a scanner
Scanner inObj= new Scanner(System.in);
System.out.println("Enter the number of paint in quarts for the painting job");
//Declare scanner object as number of jobs
numberOfJobs= inObj.nextInt();
//declaring the number of gallons
int numOfGallons = numberOfJobs / numberOfQuarts;
// declare quarts
int numOfQuarts= numberOfJobs % numberOfQuarts;
System.out.println("The painting job of "+ numberOfJobs+ " quarts requires "+ numOfGallons + " gallons and "+ numOfQuarts+ " quarts of paint.");
}
}