Last active
August 29, 2015 14:06
-
-
Save StaniTr/0809cca28e4283149eaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Exam_Problem1_DozenEggs { | |
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(System.in); | |
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] | |
eggs=eggs+Integer.parseInt(words[0]); | |
} | |
else { | |
//if no eggs then dozens->add num of dozens | |
dozens=dozens+Integer.parseInt(words[0]); | |
} | |
} | |
//result | |
sumEggs=eggs%12; | |
//dozens are equal to dozens+dozens from eggs (egss/12) | |
sumDozens=eggs/12+dozens; | |
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