Skip to main content

Posts

Showing posts with the label Booleans

Einstein's Logic Puzzle (SPOILER ALERT!)

On Monday I began working through a Discrete Math textbook in preparation for some courses I'll be taking in January. There was a beautiful logic problem in Chapter 1, apparently created by Einstein. This is one version of it: Five men with  different nationalities and with different jobs live in  con secutive houses on a street. These houses are painted  dif ferent colors. The men have different pets and have   dif ferent favorite drinks.  Determine who owns a zebra and  whose favorite drink is mineral water (which is one of the  favorite drinks) given these clues:  The Englishman lives  in the red house.  The Spaniard owns a dog.  The Japanese  man is a painter.  The Italian drinks tea.  The Norwegian  lives in the first house on the left.  The green house is  immediately to the right of the white one. The photogra pher  breeds snails.  The diplomat lives in the yellow house. ...

My First Control Structure in Java

Here is my first original program, written after 5 days of learning java. The goal was to include a looping control structure with decision making paths (if/else). ____________________________________________________________________ import java.util.Scanner; public class AverageTemp  { //Calculates the average temperature of weekdays in centigrade  public static void main(String[] args)  { Scanner keyboard = new Scanner (System.in); double monday, tuesday, wednesday,thursday,friday; char option; //User input for five weekdays do { System.out.println ("What was the average temperature on Monday?:"); monday = keyboard.nextDouble(); System.out.println ("What was the average temperature on Tuesday?:"); tuesday = keyboard.nextDouble();  System.out.println ("What was the average temperature on Wednesday?:"); wednesday = keyboard.nextDouble(); System.out.println ("What was the average temperature on Thursd...