Midterm II ICS111. Two Classes used to read user input 1.Scanner 2.BufferedReader 3.StringReader 4.1 and 2 5.1 and 3.

Slides:



Advertisements
Similar presentations
Java Control Statements
Advertisements

AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Control Flow Statements: Repetition/Looping
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
While loops.
Execute Blocks of Code Multiple Times Telerik Software Academy C# Fundamentals – Part 1.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
SE-1020 Dr. Mark L. Hornick 1 Exceptions and Exception Handling.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
Switch Statement switch (month) { case 9: case 4: case 6: case 11: days = 30; break; case 2: days = 28; if (year % 4 == 0) days = 29; break; default: days.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Flow of Control Loops – Chapter 3.2. Java Loop Statements: Outline the while Statement the do-while Statement the for Statement.
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
Java Exception Handling Handling errors using Java’s exception handling mechanism.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Java Programming Constructs 1 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
From C++ to Java A whirlwind tour of Java for C++ programmers.
Chapter 4: Loops and Files. The Increment and Decrement Operators  There are numerous times where a variable must simply be incremented or decremented.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
Lec 4: while loop and do-while loop. Review from last week if Statements if (num < 0.5){...println("heads"); } if –else Statements if (num < 0.5){...println("heads");
 The if statement and the switch statement are types of conditional/decision controls that allow your program.  Java also provides three different looping.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Decisions. Three Forms of Decision Making in Java if statements (test a boolean expression) switch statements (test an integer expression) conditional.
Exceptions Chapter 16 This chapter explains: What as exception is Why they are useful Java exception facilities.
CSE 201 – Elementary Computer Programming 1 Extra Exercises Sourceshttp://
Starting Out With Java 5 Control Structures to Objects By Tony Gaddis Copyright © 2005, Pearson Addison-Wesley. All rights reserved. Chapter 4 Slide #1.
A: A: double “4” A: “34” 4.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Lecture 01b: C++ review Topics: if's and switch's while and for loops.
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING While Loop.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Chapter 6 Controlling Program Flow with Looping Structures.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
CSE 110 Midterm Review Hans and Carmine. If Statements If statements use decision logic In order to properly use if statements relational operators must.
Information and Computer Sciences University of Hawaii, Manoa
Chapter 4 Repetition Statements (loops)
The switch Statement, and Introduction to Looping
Unit-1 Introduction to Java
Control Structures.
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Looping and Repetition
Loops October 10, 2017.
null, true, and false are also reserved.
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
The switch statement: an alternative to writing a lot of conditionals
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
Conditions and Boolean Expressions
Flow Control Statements
By Hector M Lugo-Cordero September 3, 2008
Program Flow.
Welcome back to Software Development!
Java: Variables, Input and Arrays
Chapter 3 Debugging Section 3.4
Selections and Loops By Sarah, Melody, Teresa.
CSS161: Fundamentals of Computing
Chapter 2 Sets Active Learning Lecture Slides
Presentation transcript:

Midterm II ICS111

Two Classes used to read user input 1.Scanner 2.BufferedReader 3.StringReader 4.1 and and 3

The BufferedReader may throw the following exception 1.InputMismatchException 2.StringOutOfBoundsException 3.NumberFormatException 4.IndexOutOfBoundsException 5.None

The Scanner may throw the following exception 1.InputMismatchException 2.StringOutOfBoundsException 3.NumberFormatException 4.IndexOutOfBoundsException 5.None

Integer.parseInt throws the following exception 1.InputMismatchException 2.StringOutOfBoundsException 3.NumberFormatException 4.IndexOutOfBoundsException 5.None

String s = “JAVA”; int x = s.charAt(-1); returns 1.InputMismatchException 2.IndexOutOfBoundsException 3.NumberFormatException 4.Nothing, it is blank 5.None of the above This slide changed to fix a typo

String s = “JAVA”; int x = s.charAt(2); returns 1.InputMismatchException 2.A 3.V 4.StringOutOfBoundsException 5.Nothing, it is blank 6.None of the above

if(i 25) 1.True for all numbers between 20 and 25 2.True for all numbers between 21 and 24 3.True for all numbers less than 20 and greater than 25 4.Never true

if(i 25) 1.True for all numbers between 20 and 25 2.True for all numbers between 21 and 24 3.True for all numbers less than 20 and greater than 25 4.Never True

if(i>20||i<25) 1.True for all numbers less than 20 and greater than 25 2.True for all numbers between 21 and 24 3.True for all numbers 4.Never true

if(i>20&&i<25) 1.True for all numbers less than 20 and greater than 25 2.True for all numbers between 21 and 24 3.True for all numbers 4.Never true

How many times will the loop execute? for(i=0; i<5; i=i+2){ 1.Will never execute 2.Will execute 2 times 3.Will execute 3 times 4.Will execute 4 times 5.Infinite Loop

How many times will the loop execute? for(i=0; i>5; i=i+2){ 1.Will never execute 2.Will execute 2 times 3.Will execute 3 times 4.Will execute 4 times 5.Infinite Loop

How many times will the loop execute? for(i=0; i>5; i=i-1){ 1.Will never execute 2.Will execute 2 times 3.Will execute 3 times 4.Will execute 4 times 5.Infinite Loop

How many times will the loop execute? int x = 2; while(x<5){ x=x+(x%2); } 1.Will never execute 2.Will execute 2 times 3.Will execute 3 times 4.Will execute 4 times 5.Infinite Loop

How many times will the loop execute? int x = 3; while(x<5){ x=x+(x%2); } 1.Will never execute 2.Will execute 2 times 3.Will execute 3 times 4.Will execute 4 times 5.Infinite Loop

How many times will the loop execute? int x = 18; while(x>5){ x=x-(x/3); } 1.Will never execute 2.Will execute 2 times 3.Will execute 3 times 4.Will execute 4 times 5.Infinite Loop

Switch statements work with 1.int 2.char 3.String 4.doolean 5.Any primitive data type 6.Only 1 and 2 7.Only 1,2 and 3

switch(x){ case 1: case 2: case 3: x=x+1; case 4: x=x+2; default: x=x-5; } Runing this code with x = 2, After executing the switch statement What will be the value of x?

switch(x){ case 1: x=x+1; break; case 2: x=x+2; break case 3: x=x+1; break; default: x=x-5; } Runing this code with x = 7, After executing the switch statement What will be the value of x?

switch(x){ case 1: x=x+1; case 2: x=x+2; break case 3: x=x+1; default: x=x-5; } Runing this code with x = 2, After executing the switch statement What will be the value of x?

switch(x){ case 1: x=x+1; case 2: x=x+2; break case 3: x=x+1; default: x=x-5; } Runing this code with x = 1, After executing the switch statement What will be the value of x?

String s1=“JAVA”; String s2=“javA”; boolean areEqual=false; areEqual =s1.equals(s2); areEqual is: 1.True 2.False