Consider the following code:

Slides:



Advertisements
Similar presentations
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 17.
Advertisements

Loops –For For Reading for this Lecture, L&L, Part of 5.8.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
LAB 10.
Computer Programming Lab(4).
Computer Programming Lab(5).
The for-statement. Different loop-statements in Java Java provides 3 types of loop-statements: 1. The for-statement 2. The while-statement 3. The do-while-statement.
 The pool rack example could be implemented using a for loop.  It is also possible to write recursive methods that accomplish things that you might.
Java TA Session 1. Software Java Runtime Environment (JRE) java.exe Java Development Kit (JDK) java.exe, javac.exe Version 1.6 = Version 6, Version 1.7.
Week 2 - Wednesday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Chapter 5 Case Study. Chapter 5 The RPS Flowchart.
Collection 105 Yola. To store data in RAM Variables (name all the types with their length) Arrays (one, two or more) Collections and Maps.
Assignment statements using the same variable in LHS and RHS.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
The if-else statement. The if-else statement in Java The if-else statement is the second conditional statement in Java The if-else statement selects one.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
Using methods in the Java library. Previously discussed Method = a collection of statements that performs a complex (useful) task A method is identified.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
ICBT  Basura Ramanayaka  Eshani werapitiya  Hasitha Dananjaya.
Arithmetic expressions containing Mathematical functions.
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.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Cumulative algorithms. 2 Adding many numbers How would you find the sum of all integers from ? // This may require a lot of typing int sum = 1 +
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
Working with floating point expressions. Arithmetic expressions Using the arithmetic operators: and brackets (... ), we can construct arithmetic expression.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
Computer Programming1 Computer Science 1 Computer Programming.
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
The if-else statement. Introducing the if-else statement Programming problem: Re-write the a,b,c-formula program to solve for complex number solutions.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
Fractions Part Two. How many halves are in a whole? 2 1/2.
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.
Strings CSE 1310 – Introduction to Computers and Programming
Strings CSE 1310 – Introduction to Computers and Programming
Chapter 2 Clarifications
CSC111 Quick Revision.
Strings CSE 1310 – Introduction to Computers and Programming
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
Chapter 2 Elementary Programming
Computer Programming Methodology Input and While Loop
Introduction to Methods in java
Repetition.
Data types, Expressions and assignment, Input from User
TK1114 Computer Programming
Something about Java Introduction to Problem Solving and Programming 1.
While Statement.
Conditional Loops.
חלק ה שימוש במציין שלם לערך תווי
ניתוח זמן ריצה (על קצה המזלג)
Subprograms Functions.
Student #7 starts with Locker 7 and changes every seventh door
Chapter 6 Queue.
Copyright © by Curt Hill
Self study.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Lecture Notes – Week 2 Lecture-2
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
The switch Statement When we want to compare a variable against several values to see which one it has, we can use the switch statement: switch (status)
Presentation transcript:

Consider the following code: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } Copyright © 2004-2018 - Curt Hill

Copyright © 2004-2018 - Curt Hill Now what? What is the first executable statement? The declaration is first Record the variables and their value Then step through the statements Copyright © 2004-2018 - Curt Hill

Copyright © 2004-2018 - Curt Hill First step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 Copyright © 2004-2018 - Curt Hill

Copyright © 2004-2018 - Curt Hill Second step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 2 5 Copyright © 2004-2018 - Curt Hill

Copyright © 2004-2018 - Curt Hill Third step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 Assume input line is: 7 4 -6 Copyright © 2004-2018 - Curt Hill

Copyright © 2004-2018 - Curt Hill Fourth step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 7 35 5 Copyright © 2004-2018 - Curt Hill

Copyright © 2004-2018 - Curt Hill Fifth step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 7 35 5 7 35 14 Copyright © 2004-2018 - Curt Hill

Copyright © 2004-2018 - Curt Hill Sixth-Eighth step: import java.util.Scanner; public class con { public static void main(String[] args){ int a,b=2,c=5; Scanner s = new Scanner(System.in); a = s.nextInt(); b = a*c; c = b/2 – c + 2; System.out.print(a); System.out.print(b); System.out.println(c); } a b c ? 2 5 7 2 5 7 35 5 7 35 14 Copyright © 2004-2018 - Curt Hill