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.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Chapter 3A Review boolean fun = true; if(fun) System.out.print(“yeah!”);
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
 Demonstrate use of a “for loop” in the design and development of a Java program to calculate the total of a one-dimensional array of 6 integers.  Design.
11 Methods1June Methods CE : Fundamental Programming Techniques.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
10 ThinkOfANumber program1July ThinkOfANumber program CE : Fundamental Programming Techniques.
Scoping and Recursion CSC 171 FALL 2001 LECTURE 8.
Topic 7 parameters Based on slides bu Marty Stepp and Stuart Reges from "We're flooding people with information. We.
תרגול 12 מעקב אובייקטים 1. Our exams material : Course Syllabus : includes all the material.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Do You Understand Methods and Parameters? In this section you will be shown 25 different programs. Most of these programs have some type of error. A few,
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
1 Linear and Binary Search Instructor: Mainak Chaudhuri
BUILDING JAVA PROGRAMS CHAPTER 1 ERRORS. 22 OBJECTIVES Recognize different errors that Java uses and how to fix them.
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Indentation & Readability. What does this program do? public class Hello { public static void main ( String[] args ) { //display initial message System.out.println(
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
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.
Take out a piece of paper and PEN. The quiz starts ONE minute after the tardy bell rings. You will have 45 – 90 seconds per question. Determine the output.
Output Programs These slides will present a variety of small programs. Each program has some type of array that was introduced in this chapter. Our concern.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Classes - Intermediate
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Output Programs These slides will present a variety of small programs. Each program has a compound condition which uses the Boolean Logic that was introduced.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Output Programs These slides will present a variety of small programs. Most of the programs deal with DecimalFormat objects or Polygon objects. Our concern.
Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
Lecture 3: Method Parameters
Examples of Classes & Objects
Exercise Java programming
Advanced Programming TA Session 2
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Introduction to programming in java
Building Java Programs
Advanced Programming in Java
Building Java Programs
Functions Used to write code only once Can use parameters.
March 29th Odds & Ends CS 239.
TO COMPLETE THE FOLLOWING:
PowerPoint Presentation Authors of Exposure Java
Java so far Week 7.
Topic 7 parameters "We're flooding people with information. We need to feed it through a processor. A human must turn information into intelligence or.
Code Animation Examples
CS110D Programming Language I
Recursive GCD Demo public class Euclid {
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Lecture 3: Method Parameters
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
if-else if (condition) { statements1 } else { statements2
Scope of variables class scopeofvars {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
PowerPoint Presentation Authors of Exposure Java
Perfect squares class identifySquareButLessClever {
Take out a piece of paper and PEN.
PowerPoint Presentation Authors of Exposure Java
PowerPoint Presentation Authors of Exposure Java
Java Programming with BlueJ Objectives
Scope scope: The part of a program where a variable exists. From its declaration to the end of the { } braces A variable declared in a for loop exists.
Take out a piece of paper and PEN.
PowerPoint Presentation Authors of Exposure Java
CIS 110: Introduction to Computer Programming
Quiz 11 February 13, 2019.
Presentation transcript:

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.

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.

public class Output0501 { public static void main (String args[]) { for (int x = 1; x < 8; x++) System.out.println("x = " + x); }

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

public class Output0502 { public static void main (String args[]) { for (int x = 1; x <= 8; x++) System.out.println("x = " + x); }

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

public class Output0503 { public static void main (String args[]) { for (int x = 0; x <= 8; x+=2) System.out.println("x = " + x); }

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

public class Output0504 { public static void main (String args[]) { for (int x = 100; x > 0; x-=20) System.out.println("x = " + x); }

public class Output0504 { public static void main (String args[]) { for (int x = 100; x > 0; x-=20) System.out.println("x = " + x); } xOutput 100x = x = 80 60x = 60 40x = 40 20x = 20

public class Output0505 { public static void main (String args[]) { for (int x = 1; x < 100; x*=2) System.out.println("x = " + x); }

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

public class Output0506 { public static void main (String args[]) { for (int x = 729; x >= 1; x/=3) System.out.println("x = " + x); }

public class Output0506 { public static void main (String args[]) { for (int x = 729; x >= 1; x/=3) System.out.println("x = " + x); } xOutput 729x = x = x = 81 27x = 27 9x = 9 3x = 3 1x = 1

public class Output0507 { public static void main (String args[]) { int x = 100; if (x == 100) System.out.println("Hello"); }

public class Output0507 { public static void main (String args[]) { int x = 100; if (x == 100) System.out.println("Hello"); } xx == 100?Output 100trueHello

public class Output0508 { public static void main (String args[]) { int x = 99; if (x == 100) System.out.println("Hello"); }

public class Output0508 { public static void main (String args[]) { int x = 99; if (x == 100) System.out.println("Hello"); } xx == 100?Output 99false[none]

public class Output0509 { public static void main (String args[]) { int x = 101; if (x > 100) System.out.println("Hello"); else System.out.println("Goodbye"); }

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

public class Output0510 { public static void main (String args[]) { int x = 100; if (x > 100) System.out.println("Hello"); else System.out.println("Goodbye"); }

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

public class Output0511 { public static void main (String args[]) { int x = 100; if (x >= 100) System.out.println("Hello"); else System.out.println("Goodbye"); }

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

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); }

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 y = 7

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); }

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 x = 10 y = 18

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); }

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 x = 8 y = 13 z = -5

public class Output0515 { public static void main (String args[]) { while (2 + 2 == 4) { System.out.print("EXPOJAVA"); }

public class Output0515 { public static void main (String args[]) { while (2 + 2 == 4) { System.out.print("EXPOJAVA"); }