mid1solns

mid1solns - CMPS 12A Introduction Programming Winter 2008...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CMPS 12A Introduction Programming Winter 2008 Midterm Exam 1 Solutions 1. (20 Points) Trace the following Java program and place the output on the lines below exactly as it would appear on the screen. Assume that the user enters 1 3 5 at the first prompt, and 1.5 2.0 2.5 at the second prompt. (Note: there are more lines printed below than are actually needed.) // problem1.java import java.util.Scanner; class problem1{ public static void main(String args){ Scanner sc = new Scanner(System.in); int a, b, c; double x, y, z; System.out.print("Enter three integers: "); a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); System.out.print("Enter three doubles: "); x = sc.nextDouble(); y = sc.nextDouble(); z = sc.nextDouble(); a = (++c)-(b++); x += z - y; b *= b; y = c*z; c = (int)(b - x); System.out.println("a="+a+", b="+b+", c="+c); System.out.println("x="+x+", y="+y+", z="+z); System.out.println("c/a="+c/a); System.out.println("c%a="+c%a); } } Output: Enter three integers: 1 3 5 Enter three doubles: 1.5 2.0 2.5 a=3, b=16, c=14 x=2.0, y=15.0, z=2.5 c/a=4 c%a=2 2.2....
View Full Document

This note was uploaded on 09/15/2011 for the course CMPS 12A taught by Professor Mcdowell during the Winter '08 term at UCSC.

Page1 / 5

mid1solns - CMPS 12A Introduction Programming Winter 2008...

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

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