Monday 23 March 2020

COUNTING NUMBERS OF EGG IN FORM OF GROSS AND DOZEN USING JAVA LANGUAGE

Q-24- If you have N eggs, then you have N/12 dozen eggs, with N%12 eggs left over. (This is essentially the definition of the / and % operators for integers.) Write a java program that asks the user how many eggs she has and then tells the user how many dozen eggs she has and how many extra eggs are left over. A gross of eggs is equal to 144 eggs. Extend your program so that it will tell the user how many gross, how many dozen, and how many left over eggs she has. For example, if the user says that she has 1342 eggs, and then your program would respond with 

        Your number of eggs is 9 gross, 3 dozen, and 10.

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int number;
System.out.println("Enter The Number Of Eggs: ");
number=sc.nextInt();
int gross=number/144;
int a=number%144;
int dozen=a/12;
int b=a%12;
System.out.println("Your Number Of Eggs Is "+gross+" gross ,"+dozen+" dozen ,"+" and "+b);
}


}

OUTPUT :
Enter The Number Of Eggs:
1324

Your Number Of Eggs Is 9 gross ,2 dozen , and 4

No comments:

Post a Comment