// ******************************************************************* // Average.java // // Read three integers from the user and print their average // ******************************************************************* public class Average { public static void main(String[] args) { int val1, val2, val3; double average; // get three values from user System.out.println("Please enter three integers and " + "I will compute their average"); ____________________________________ ____________________________________ ____________________________________ //compute the average ____________________________________ //print the average ____________________________________ } }
int a = 3, b = 10, c = 7; double w = 12.9, y = 3.2;
// File: Errors.java // Purpose: A program with lots of syntax errors // Correct all of the errors (STUDY the program carefully!!) #import java.util.Scanner; public class errors { public static void main (String[] args) { String Name; / Name of the user int number; int numSq; Scanner myInput = new Scanner(System.in); System.out.print ("Enter your name, please: ") Name = myInput.nextInt(); System.out.print ("What is your favorite number?); number = myInput.nextInt(); numSq = number * number; System.out.println (Name ", the square of your number is " numSquared); }
// FILE: Trace.java // PURPOSE: An exercise in tracing a program and understanding // assignment statements and expressions. import java.util.Scanner; public class Trace { public static void main (String[] args) { int one, two, three; double what; Scanner myInput = new Scanner(System.in); System.out.print ("Enter two integers: "); one = myInput.nextInt(); two = myInput.nextInt(); System.out.print("Enter a floating point number: "); what = myInput.nextDouble(); three = 4 * one + 5 * two; two = 2 * one; System.out.println ("one " + two + ":" + three); one = 46 / 5 * 2 + 19 % 4; three = one + two; what = (what + 2.5) / 2; System.out.println (what + " is what!"); } }