Midterm preview. double int = 2.0; True / FalseThe following is a syntactically correct variable declaration and assignment statement:

Slides:



Advertisements
Similar presentations
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.
Advertisements

This is Java Jeopardy.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
 2005 Pearson Education, Inc. All rights reserved Introduction.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Outline Java program structure Basic program elements
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Smoking is prohibited 1 CS 101 First Exam Review.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
CSM-Java Programming-I Spring,2005 Control Flow Lesson - 3.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
***** SWTJC STEM ***** Chapter 2-2 cg Identifiers - Naming Identifier, the name of a Java programming component. Identifier naming rules... Must.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 9 Clicker Questions September 29, 2009.
The Java Programming Language
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
First Programs CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
CS177 Week2: Recitation Primitive data types and Strings with code examples.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
Decisions, Decisions, Decisions Conditional Statements In Java.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
CSE 201 – Elementary Computer Programming 1 Extra Exercises Sourceshttp://
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Variables and Constants Chapter 4 Review. Declaring Variables A variable is a name for a value stored in memory. Variables and constants are used in programs.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Question 01 Which of the following can be stored by a simple or primitive data type? (a)Only 1 single value (b)Only Attributes (c)Only Methods (d)Both.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Midterm preview.
Information and Computer Sciences University of Hawaii, Manoa
Basic concepts of C++ Presented by Prof. Satyajit De
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Elementary Programming
Chapter 2 Elementary Programming
Introduction to Computer Science / Procedural – 67130
Lecture 2 Data Types Richard Gesick.
GC211Data Structure Lecture2 Sara Alhajjam.
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Chapter 6 More Conditionals and Loops
Primitive Data, Variables, Loops (Maybe)
Data types and variables
SELECTION STATEMENTS (1)
Chapter 2.
OPERATORS (2) CSC 111.
Introduction to C++ Programming
An Introduction to Java – Part I, language basics
Building Java Programs
Building Java Programs
Building Java Programs
elementary programming
Focus of the Course Object-Oriented Software Development
Chapter 2 Programming Basics.
Building Java Programs
PROGRAM FLOWCHART Iteration Statements.
Just Enough Java 17-May-19.
Building Java Programs
Presentation transcript:

Midterm preview

double int = 2.0; True / FalseThe following is a syntactically correct variable declaration and assignment statement:

The diagram in Figure 1a is the decision structure logic of the Java statements in Figure 1b. if (Condition_1){ if (Condition_2){ Statement_B; }else{ Statement_C; } if (! Condition_1){ Statement_A; } Figure 1aFigure 1b True / False

Java is a case sensitive programming language. True / False

letter = “a”; True / FalseAssuming that letter has been declared as a variable of type char, the below statement is syntactically correct:

True / False For the logical AND operator, &&, which connects two boolean expressions, both expressions must be false for the overall expression to be false. True / False

int someVariable = 0; System.out.println(“Output : “ + someVariable); int someVar1 = 1, someVar2 = 2; System.out.println(“Output : “ + someVar1 / someVar2); The below two pieces of code output the same thing to the console:

True / False Syntax errors are mistakes that the programmer has made that violate the rules of the programming language.

True / False The following Java code is syntactically incorrect:

True / False The following piece of Java code is syntactically correct:

True / False The equality operator, ==, cannot be used to compare the values stored in two variables of type String. You can compare the values of the variables, but not actual String values.

if (x > -1 && x < 100) Assuming x has been declared as a variable of type int, the below Java code in the box is equivalent to which of the logical statements? A.If x is greater than 0 and x is less than 99 B.If x is greater than 1 and x is less than 99 C.If x is (0 or greater) and x is less than 99 D.If x is (0 or greater) and x is at most 99

if (x > -1 && x < 100) What does the following piece of Java code output: A.heya B.Heya C.HeYa D.HEYA String sentence = “heya”; System.out.println(sentence.toLowerCase());

13.Major components of a typical modern computer consist of: A.The Central Processing Unit B.Input/output devices C.Secondary storage devices D.All of the above

if (x > -1 && x < 100) What will be the values of x and y after the following code is executed? A.x = 24, y = 7 B.x = 24, y = 8 C.x = 25, y = 7 D.x = 25, y = 8 E.x = 26, y = 7 F.x = 26, y = 8 int x = 25, y = 8; x += (7-y); y--;

if (x > -1 && x < 100) What would be the value of percentVal after the following statements are executed? A.x = 24, y = 7 B.x = 24, y = 8 C.x = 25, y = 7 D.x = 25, y = 8 E.x = 26, y = 7 F.x = 26, y = 8 double percentVal = 0.0; int purchase = 950; char cust = 'N'; if (purchase > 1000){ if (cust == 'Y') percentVal =.05; else percentVal =.04; } else { if (cust == 'Y') percentVal =.03; else percentVal =.02; } percentVal =.05; A.0.05 B.0.04 C.0.03 D.0.02 E. 0.01

if (x > -1 && x < 100) For the below Java code, circle any portion that contains a syntax error. Circle those parts of the Java code where there is a mistyped character, missing semicolon, etc. A.x = 24, y = 7 B.x = 24, y = 8 C.x = 25, y = 7 D.x = 25, y = 8 E.x = 26, y = 7 F.x = 26, y = 8 public class HowMuchTimeRemaining public static void main (String[] args){ timeRemaining double = 12.5; timeSinceStart double = 33.0; if (timEremaining =< ){ System.out.println("Less than 10 minutes left.") } else if (timeRemaining < ){ System("Less than but more than minutes left.") } else { System.out.println("Ahh. At least 20 minutes remaining.") } } } Please plug this code in your jGrasp to catch all the errors…

Explain the following line of code (do NOT predict the value of x; explain what the statement does). final int x = 10/5; Your Answer : x is going to be equal 2, one can not change it’s value after this assignment because x is declared “final”.

int y = 1; while (y < 10){ y += 3; } What is the value of y after the following code is executed? 10

public class MidtermQuestion { public static void main (String[] args){ String cwu = "Central Washington University"; System.out.print(cwu.substring(0,1)); System.out.println(cwu.substring(cwu.length()-3,cwu.length())); } } What is the output of the following Java Program? Your Answer : ________________________________________________

The binary encoding is equivalent to what base-10 number? Show your work to receive partial credit, in the case that your answer is incorrect. Your Answer : 14

Write a one-line syntactically correct Java statement that declares a variable animal of type String and assigns it the value tiger Your Answer: String animal = “tiger”;

// A program that prints the even integers // from 2 through (and including) 50 public class EvenNumFrom2Through50 { // the main routine public static void main (String[] args) { for (int I = 2; I =< 50; I +=2;) { System.out.println(i); } } } Write a Java program that will print to the console all even integers starting from 2 through (and including) 50. Complete the program, which has been started for you. Hint: you can use a while or for loop. Hint 2: One correct solution requires only 3 lines of VERY simple code.

Which of the following statements is/are true about comments. A.A single line comment begins with the characters \\ B.A multiple-line comment begins with */ C.The following is a syntactically correct comment: // */ */ ////////// D.Single-line comments are ignored by the compiler E.Multiple-line comments are not ignored by the compiler F.Multiple-line comments must end with the characters /*

for (int i=-1; i<10; i+=2){ System.out.print(i); } Based on the for-loop shown below, which of the lettered choice is/are correct? A.The body of the for-loop will be executed 5 times B.The i+=2 part of the for loop will be performed 5 times C.The output produced by the for loop will be D.The i+=2 part of the for loop is performed as many times as the i<10 check is performed E.The i<10 part of the for loop is the initialization portion, and is executed only once F.The i+=2 part of the for loop is executed at least once.