# ex3a - fill in reading timesOlder...

This preview shows page 1. Sign up to view the full content.

/* DreadedAlgebra * author: Diana Franklin * purpose: Solve a common problem given to algebra students * Illustrate how to manipulate algebra to be in the format * solution = calculation * Show some new ways to output using print, printf */ import java.util.Scanner; public class DreadedAlgebra{ public static void main(String[] args) { // declare variables int timesOlder, timesJake, minus; float jan, jake; Scanner keyboard; //allocate, and initialize the Scanner keyboard = new Scanner( System.in ); // ask for and read in user input System.out.println("Welcome to the Dreaded Algebra Age Problem"); System.out.print("Jan is how many times older than Jake? "); // fill in reading timesJake System.out.print("The sum of their ages is how many times"); System.out.print(" Jake's age, minus some? ");
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // fill in reading timesOlder System.out.printf("The sum of their ages is %d times", timesJake); System.out.print(" Jake's age minus how many? "); // fill in reading minus // print out the problem System.out.printf("Jan is %dx as old as Jake.\n",timesOlder); System.out.printf("The sum of their ages is %d times ", timesJake); System.out.println("Jake's age less " + minus); System.out.printf("How old are Jan and Jake?\n"); // calculate the result (fill this in) // print out the result System.out.println("The solution is: "); System.out.printf("Jan is %3.1f and Jake is %3.1f!\n", jan, jake); System.out.println("Goodbye"); } // end of main } // end of class Dreaded Algebra...
View Full Document

## This note was uploaded on 12/27/2011 for the course CMPSC 5 taught by Professor Franklin during the Fall '09 term at UCSB.

Ask a homework question - tutors are online