Data Expressions(1) - Data Expressions(1) Java Programming...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Data Expressions(1) Java Programming Lab Exercises Topics Lab Exercises Variables Prelab Exercises Constants Area and Circumference of a Circle Assignment Painting a Room Submitting your assignment in WebCT Vista Your task is to submit your assignment under the supervision of your instructor: o Upload this file (DataExpressions(1).rtf) with your answers to the assignment box in WebCT for this lab class. o Upload your programs (Errors.java, Circle.java, Circle2.java, Circle3.java, and Paint.java) to the assignment box in WebCT for this lab class. Data Expressions(1) 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Prelab Exercises 1. What is the difference between a variable and a constant? 2. Explain what each of the lines below does. Be sure to indicate how each is different from the others. a. int x; b. int x = 3; c. x = 3; 3. The following program reads three integers and prints the average. Fill in the blanks so that it will work correctly. // ******************************************************************* // Average.java // // Read three integers from the user and print their average // ******************************************************************* import java.util.Scanner; public class Average { public static void main(String[] args) { int val1, val2, val3; double average; Scanner scan = new Scanner(System.in) ; // get three values from user System.out.println("Please enter three integers and " + "I will compute their average"); ____________________________________ ____________________________________ ____________________________________ //compute the average ____________________________________ //print the average ____________________________________ } } 2 Data Expressions(1)
Background image of page 2
4. Given the declarations below, find the result of each expression. int a = 3, b = 10, c = 7; double w = 12.9, y = 3.2; a. a + b * c b. a - b - c c. a / b d. b / a e. a - b / c f. w / y g. y / w h. a + w / b i. a % b / y j. b % a k. w % y 5. Carefully study the following program and find and correct all of the syntax errors. // 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 scan = new Scanner(System.in); System.out.print ("Enter your name, please: ") Name = scan.nextInt(); System.out.print ("What is your favorite number?); number = scan.nextInt(); numSq = number * number; System.out.println (Name ", the square of your number is " numSquared); } Data Expressions(1) 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6. Trace the execution of the following program assuming the input stream contains the numbers 10, 3, and 14.3. Use a
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/31/2010 for the course CPSC 1301 taught by Professor Khan,s during the Spring '08 term at Columbus State University.

Page1 / 7

Data Expressions(1) - Data Expressions(1) Java Programming...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online