Download presentation
Presentation is loading. Please wait.
Published byHarvey Owen Modified over 8 years ago
2
Output Programs These slides will present a variety of small programs. Each program has a control structure that was introduced in this chapter. Our concern will be with the output of each program, and more importantly, to develop a way to determine program output correctly for programs that involve control structures. You can expect that on quizzes and/or tests only a program segment or a method is shown.
3
Teacher/Student Versions, Tablet PCs, and Inking The “For Teachers” version of this presentation has 2 slides for each program. The first slide only shows the program. The second shows the program, worked out solution, and output. The “For Students” version only has 1 slide for each program with no provided solution or output. Students are expected to work out the solutions either on paper, or ideally they can “ink” directly on their laptops.
4
public class Output0501 { public static void main (String args[]) { for (int x = 1; x < 8; x++) System.out.println("x = " + x); }
5
public class Output0501 { public static void main (String args[]) { for (int x = 1; x < 8; x++) System.out.println("x = " + x); } xOutput 1x = 1 2x = 2 3x = 3 4x = 4 5x = 5 6x = 6 7x = 7
6
public class Output0502 { public static void main (String args[]) { for (int x = 1; x <= 8; x++) System.out.println("x = " + x); }
7
public class Output0502 { public static void main (String args[]) { for (int x = 1; x <= 8; x++) System.out.println("x = " + x); } xOutput 1x = 1 2x = 2 3x = 3 4x = 4 5x = 5 6x = 6 7x = 7 8x = 8
8
public class Output0503 { public static void main (String args[]) { for (int x = 0; x <= 8; x+=2) System.out.println("x = " + x); }
9
public class Output0503 { public static void main (String args[]) { for (int x = 0; x <= 8; x+=2) System.out.println("x = " + x); } xOutput 0x = 0 2x = 2 4x = 4 6x = 6 8x = 8
10
public class Output0504 { public static void main (String args[]) { for (int x = 100; x > 0; x-=20) System.out.println("x = " + x); }
11
public class Output0504 { public static void main (String args[]) { for (int x = 100; x > 0; x-=20) System.out.println("x = " + x); } xOutput 100x = 100 80x = 80 60x = 60 40x = 40 20x = 20
12
public class Output0505 { public static void main (String args[]) { for (int x = 1; x < 100; x*=2) System.out.println("x = " + x); }
13
public class Output0505 { public static void main (String args[]) { for (int x = 1; x < 100; x*=2) System.out.println("x = " + x); } xOutput 1x = 1 2x = 2 4x = 4 8x = 8 16x = 16 32x = 32 64x = 64
14
public class Output0506 { public static void main (String args[]) { for (int x = 729; x >= 1; x/=3) System.out.println("x = " + x); }
15
public class Output0506 { public static void main (String args[]) { for (int x = 729; x >= 1; x/=3) System.out.println("x = " + x); } xOutput 729x = 729 243x = 243 81x = 81 27x = 27 9x = 9 3x = 3 1x = 1
16
public class Output0507 { public static void main (String args[]) { int x = 100; if (x == 100) System.out.println("Hello"); }
17
public class Output0507 { public static void main (String args[]) { int x = 100; if (x == 100) System.out.println("Hello"); } xx == 100?Output 100trueHello
18
public class Output0508 { public static void main (String args[]) { int x = 99; if (x == 100) System.out.println("Hello"); }
19
public class Output0508 { public static void main (String args[]) { int x = 99; if (x == 100) System.out.println("Hello"); } xx == 100?Output 99false[none]
20
public class Output0509 { public static void main (String args[]) { int x = 101; if (x > 100) System.out.println("Hello"); else System.out.println("Goodbye"); }
21
public class Output0509 { public static void main (String args[]) { int x = 101; if (x > 100) System.out.println("Hello"); else System.out.println("Goodbye"); } xx > 100?Output 101trueHello
22
public class Output0510 { public static void main (String args[]) { int x = 100; if (x > 100) System.out.println("Hello"); else System.out.println("Goodbye"); }
23
public class Output0510 { public static void main (String args[]) { int x = 100; if (x > 100) System.out.println("Hello"); else System.out.println("Goodbye"); } xx > 100?Output 100falseGoodbye
24
public class Output0511 { public static void main (String args[]) { int x = 100; if (x >= 100) System.out.println("Hello"); else System.out.println("Goodbye"); }
25
public class Output0511 { public static void main (String args[]) { int x = 100; if (x >= 100) System.out.println("Hello"); else System.out.println("Goodbye"); } xx >= 100?Output 100trueHello
26
public class Output0512 { public static void main (String args[]) { int x = 0; int y = 0; while (x < 10) { y = x + 2; x = y + 3; } System.out.println("y = " + y); }
27
public class Output0512 { public static void main (String args[]) { int x = 0; int y = 0; while (x < 10) { y = x + 2; x = y + 3; } System.out.println("y = " + y); } yxOutput 00 25 710y = 7
28
public class Output0513 { public static void main (String args[]) { int x = 0; int y = 0; while (x < 10) { y = x * 2; x++; } System.out.println("x = " + x); System.out.println("y = " + y); }
29
public class Output0513 { public static void main (String args[]) { int x = 0; int y = 0; while (x < 10) { y = x * 2; x++; } System.out.println("x = " + x); System.out.println("y = " + y); } yxOutput 00 01 22 43 64 85 106 127 148 169 1810x = 10 y = 18
30
public class Output0514 { public static void main (String args[]) { int x = 1; int y = 3; int z = 5; while (z > x + y) { x = y + z; y = x + z; z = x - y; } System.out.println("x = " + x); System.out.println("y = " + y); System.out.println("z = " + z); }
31
public class Output0514 { public static void main (String args[]) { int x = 1; int y = 3; int z = 5; while (z > x + y) { x = y + z; y = x + z; z = x - y; } System.out.println("x = " + x); System.out.println("y = " + y); System.out.println("z = " + z); } xyzOutput 135 813-5x = 8 y = 13 z = -5
32
public class Output0515 { public static void main (String args[]) { while (2 + 2 == 4) { System.out.print("EXPOJAVA"); }
33
public class Output0515 { public static void main (String args[]) { while (2 + 2 == 4) { System.out.print("EXPOJAVA"); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.