public class Calculator extends ConsoleProgram { public void run() { int first = readInt("First: "); int second = readInt("Second: "); int sum = first + second; System.out.println(sum); } }
Rewrite this program to work in "real" Java below:
|
public class TrickyJava extends ConsoleProgram { public void run() { int candyBars = 20; int friends = 5; System.out.println("Candy bars: " + candyBars); System.out.println("Friends: " + friends); int candyBarsPerPerson = candyBars / friends; // We expect it to be 4... and it is 4. System.out.println("Candy per person: " + candyBarsPerPerson); friends++; System.out.println("Candy bars: " + candyBars); System.out.println("Friends: " + friends); // We expect it to be 3.33.. and it is .. candyBarsPerPerson = candyBars / friends; System.out.println("Candy per person: " + candyBarsPerPerson); } }
Write a program to calculate the number of gallons of paint needed to paint a room if:
Given 2 int values, print the smallest number if both numbers are >0, or print the largest number if they are both < 0. Otherwise print "out of range"