Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import java.util.Scanner;
public class Exam_Task1 {
public static void main(String[] args) {
//keeps num of eggs
int eggs=0;
//keeps num of dozens;
int dozens=0;
//keeps sum of eggs;
int sumEggs=0;
//keeps sum of dozens
int sumDozens=0;
String egg="eggs";
Scanner scanner = new Scanner(;
for (int i = 0; i < 7; i++) {
String text = scanner.nextLine();
//split numbers from string ("eggs" or "dozens")
String[] words = text.split(" ");
//check if the input is eggs
if ("eggs".equals(words[1])){
//add the number of eggs in [eggs]
else {
//if no eggs then dozens->add num of dozens
//dozens are equal to dozens+dozens from eggs (egss/12)
System.out.println(sumDozens+" dozens + "+sumEggs+" eggs");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment