int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);

Slides:



Advertisements
Similar presentations
The Important Thing About By. The Important Thing About ******** The important thing about ***** is *****. It is true s/he can *****, *****, and *****.
Advertisements

Java Control Statements
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
Dependency Test in Loops By Amala Gandhi. Data Dependence Three types of data dependence: 1. Flow (True) dependence : read-after-write int a, b, c; a.
For(int i = 1; i
© A+ Computer Science - if-else if-else if switch case © A+ Computer Science -
What is output line of the following C++ code? Please trace int i = 1, QP; DATA: 4, B, 3, A double credit, totCredit=0.0; double num = 0.0; string LG;
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt WHILE.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
Discussion1 Quiz. Q1 Which of the following are invalid Java identifiers (variable names)? a) if b) n4m3 c) Java d) e) DEFAULT_VALUE f) bad-choice.
L5:CSC © Dr. Basheer M. Nasef Lecture #5 By Dr. Basheer M. Nasef.
X=0 x
Conditionals – if - else Dr. Sajib Datta
[ ] Review Exam [ ] Questions [ ] Lab 6 [ ] HW6 [ ] Method Block Diagram [ ] Methods, methods [ ] Looping constructs [ ] for loop [ ] ++, -- (Thursday)
CMPUT 101 Lab # 5 October 22, :00 – 17:00.
1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
Lecture 11. Today’s topic Conditional statement –Relational operators –if statement –if-else statement –If-elseif statement.
COMP 110 Switch Statements and Loops Tabitha Peck M.S. February 6, 2008 MWF 3-3:50 pm Philips
Switch Statements. Switch Statement Often you want to do a series of tests –if i==0 … else if i==1 …. else if i==2 … else if i==3 …. C++ provides the.
“Here we go Loop de Loo” (Looping) So far you have learned (I hope) some decision making C++ control structures: *if (condition) else *if (condition) else.
computer
Flow Control in Java. Controlling which instruction to execute next Sequential  Similar to walking, one step after another Branching  Similar to a fork.
Page 1 Quiz by Joseph Lindo. Page 2 Program Analysis by providing the output of a program snippet Some are true or false Some have choices.
Simple Control Structures IF, IF-ELSE statements in C.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Flow Control in Java. Controlling which instruction to execute next Sequential  Similar to walking, one step after another Branching  Similar to a fork.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Characters and Strings. Characters  New primitive char  char letter; letter = ‘a’; char letter2 = ‘C’;  Because computers can only represent numbers,
CSC 107 – Programming For Science. Today’s Goal  Discuss writing functions that return values  return statement’s meaning and how it works  When and.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
1 CSC103: Introduction to Computer and Programming Lecture No 19.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
A: A: double “4” A: “34” 4.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
Lesson thirteen Conditional Statement "if- else" ©
1 9/26/05CS150 Introduction to Computer Science 1 Life is Full of Alternatives.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Dr. Sajib Datta Jan 23,  A precedence for each operator ◦ Multiplication and division have a higher precedence than addition and subtraction.
Chapter five exercises. a. false; b. true; c. false; d. true; e. true; f. true; g. true; h. false.
1 float Data Type Data type that can hold numbers with decimal values – e.g. 3.14, 98.6 Floats can be used to represent many values: –Money (but see warning.
for( 起始條件 ; 判斷式 ; 條件運算 ){ // 迴圈內容 } while( 判斷式 ){ // 迴圈內容 } do{ // 迴圈內容 } while( 判斷式 ) ;
Java for Beginners University Greenwich Computing At School DASCO
Section 3 Review Mr. Crone.
Compound Condition Break , Continue Switch Statements in Java
Decisions Chapter 4.
Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
C# and the .NET Framework
TK1114 Computer Programming
Flow Control in Java.
CS149D Elements of Computer Science
Review Operation Bingo
Computers & Programming Languages
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
SELECTION STATEMENTS (2)
IF Statements.
What output is produced by the following fragment?
Relational, Logical, and Equality Operators
SELECTIONS STATEMENTS
Nate Brunelle Today: Conditional Decision Statements
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
CS150 Introduction to Computer Science 1
Composition & Inverses Review
Life is Full of Alternatives Part 3
Presentation transcript:

int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);

int num = 22;//Formatted to show computer processing if (num > 0)// True { if (num % 5 == 0)// False System.out.println(num); else // Default response System.out.println(num + “ is negative”); }

int num = 22;//How programmer intended formatting if (num > 0)// True { if (num % 5 == 0)// False System.out.println(num);}else System.out.println(num + “ is negative”);

int x = 30, y = 40; if (x >= 0) { if (x <= 100) { y = x * 3; if (y < 50) x /= 10; }else y = x * 2; }else y = -x;

int x = 30, y = 40; if (x >= 0)// True { if (x <= 100)// True { y = x * 3;// y = 90 if (y < 50)//False; x stays 30 x /= 10; }else y = x * 2; }else y = -x;

a. same b. abc c. ABC d. sameabc e. there is no output

a. same b. abc c. ABC d. sameabc e. there is no output

a. 14 b. 23 c. 34 d. 4 e. 12

a. 14 b. 23 c. 34 d. 4 e. 12