J a v a Quiz (Unit 3, Test 0 Practice)

Size: px
Start display at page:

Download "J a v a Quiz (Unit 3, Test 0 Practice)"

Transcription

1 Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points if correct on the first try, but only 1 point if right on the second try. Each multiple-choice question has only one correct answer (we think). 1 st 2 nd 1. The program fragment int n, sum = 0, count = 0; do n = in.nextint(); sum += n; count++ ; while (n!= -1); System.out.println( sum / count ); is applied to the keyboard input What will be the output? A. 4 B. 4.0 C. 2.3 D. 3 E. 2 Summer, 2006 Dr. H. H. Leitner

2 Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 2. Which one of the following is a syntactically valid boolean expression whose value is true? A. ((7 < 3)! False) B. ((5 < 4) && (3 * 3 > 8)) C. ((3 < 5) = false) D. (5 >= 5 > 3) E. (1!= 2 5 == 6) 3. Assuming variable n has been properly declared as an int, the statement switch (n) case 1: System.out.println("The number is 1" ); case 2: System.out.println("The number is 2" ); break; default: System.out.println("The number is not 1 or 2"); A. Contains a syntax error, and therefore won t compile. B. Can never print the message "The number is 2" C. Is equivalent to: if (n==1) System.out.println( "The number is 1" ); else if (n==2) System.out.println( "The number is 2" ); else System.out.println("The number is not 1 or 2"); D. Will always print "The number is 2" when n equals 1 E. Will cause an execution error whenever n has a value less than 1. Summer, 2006 Dr. H. H. Leitner

3 Computer Science S-111a: Intensive Introduction to Computer Science Using Java Page 3 4. The expression (int) (Math.random() * 9-3) produces integer values in the range A. 0 to 6, inclusive B. 0 to 5, inclusive C. 3 to 11, inclusive D. -3 to 5, inclusive E. none of the above 5. Suppose the following code fragment is executed, String s = in.nextline(); char ch = s.charat(s.length() 3); and the input that the user types on the keyboard in response to this code consists of S-111a ROCKS The character variable ch now contains: A. a newline character B. 'S' C. 'K' D. 'C' E. 'O'

4 Computer Science S-111a: Intensive Introduction to Computer Science Using Java Page 4 6. The following complete program is designed to compute the number of decimal digits, ndigits, in an integer x (where x 0). class Prob6 public static void main (String [] args) int power = 1, ndigits, x; System.out.print("Input a value greater than 0: "); x = in.nextint(); while (x > power) power = * 10; ndigits ++; System.out.println("Number of digits is " + ndigits ); Find and correct three small, distinct errors in this code so that it will work as intended, even if x is a power of 10. There might be more than 3 errors, but you need to fix just 3 of them. 7. Consider the creation of a Time class, the values of which represent a time object containing an hour and a minute within a single day. In this problem you will work with the following methods: a constructor method for creating Time objects; an addminutes method to increment a Time object, returning a new Time object a tostring method to output a Time object; and a priorto method to compare two Time objects (to determine which is earlier ) For example, a method that uses this class might contain the following: Time dawn = new Time(6, 35); // creates the AM value 6:35 Time dusk = dawn.addminutes(60*12); // creates the PM value 18:35 Time m = new Time (0, 0); // creates the midnight value System.out.println ( dawn ); System.out.println ( dusk ); System.out.println ( m ); if (m.priorto(dusk)) System.out.println("Hello");

5 Computer Science S-111a: Intensive Introduction to Computer Science Using Java Page 5 This code will print 6:35 AM 6:35 PM Midnight Hello Your task is to replace each of the five??????????s with correct Java code. Note that tostring() should return time values in an intelligent fashion. The dusk value was not output as 18:35, but (correctly) instead as 6:35 PM. Similarly, a Time value whose number of minutes is less than 10 should contain a zero in the output (e.g., 11:05 AM would be printed, and not 11:5 AM). class Time private int hour, minute; public Time (int h, int m)??????????1 public Time addminutes (int m) int totalminutes = (60*hour + minute + m) % (24*60); if (totalminutes < 0) totalminutes = totalminutes + 24*60; return??????????2 public String tostring () if ((hour == 0) && (minute == 0)) return "midnight"; else if (??????????3 ) return "noon"; else??????????4 public boolean priorto (Time t)??????????5

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

Multiple Choice Questions (20 points)

Multiple Choice Questions (20 points) CSC142 Midterm 1 1 Multiple Choice Questions (20 points) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Fill the correct bubble on your scantron sheet. Each correct answer is worth

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

More information

Conditionals (with solutions)

Conditionals (with solutions) Conditionals (with solutions) For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87;

More information

CS170 Lab 11 Abstract Data Types & Objects

CS170 Lab 11 Abstract Data Types & Objects CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

More information

COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4

More information

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75 Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

More information

System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

System.out.println(\nEnter Product Number 1-5 (0 to stop and view summary) : Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Part I:( Time: 90 minutes, 30 Points)

Part I:( Time: 90 minutes, 30 Points) Qassim University Deanship of Educational Services Preparatory Year Program- Computer Science Unit Final Exam - 1434/1435 CSC111 Time: 2 Hours + 10 Minutes 1 MG Student name: Select the correct choice:

More information

Statements and Control Flow

Statements and Control Flow Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

Strings in Java String Objects

Strings in Java String Objects Strings in Java are objects. They are instances of the class String (in the package java.lang). As is the case with other objects, String variables are actually references to a String object in memory.

More information

LOOPS CHAPTER CHAPTER GOALS

LOOPS CHAPTER CHAPTER GOALS jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement

More information

THE JAVA SWITCH STATEMENT

THE JAVA SWITCH STATEMENT THE JAVA SWITCH STATEMENT Like the if-else statement, the switch statement introduces a fork in the road for the program s execution path. Unlike the if-else (1) the switch statement s fork has many tines

More information

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013 Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

COUNTING LOOPS AND ACCUMULATORS

COUNTING LOOPS AND ACCUMULATORS COUNTING LOOPS AND ACCUMULATORS Two very important looping idioms are counting loops and accumulators. A counting loop uses a variable, called the loop control variable, to keep count of how many cycles

More information

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16

CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 CSI 333 Lecture 2 Introduction to C: Part I 2 1 / 16 Basics of C Remark: Skim Chapters 1 through 6 of Deitel & Deitel. You will notice the following: C is (more or less) a subset of Java. (So, you are

More information

CMPU102: Exam 1 Solutions Spring 2005

CMPU102: Exam 1 Solutions Spring 2005 CMPU102: Exam 1 Solutions Spring 2005 1. Consider the following statements: int a = 4; int b = 7; b *= a; What are the resulting values of a and b? a = 4 b = 28 2. Consider the following statements: int

More information

Methods in Java Passing Parameters

Methods in Java Passing Parameters To make methods more flexible, we often want to give them different values to use in their processing and calculations. Consider the following method, which outputs any character a specified number of

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Standard printing function in C is printf Prints everything numbers, strings, etc. May be complex to use. Standard C library is called libc

Standard printing function in C is printf Prints everything numbers, strings, etc. May be complex to use. Standard C library is called libc Arrays and Structs and Pointers, Oh My! Programming in C Input and output Using printf Standard input and output Pointers Arrays Structures Combining these things together Arrays and Structs and Pointers,

More information

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators

More information

AP Computer Science Static Methods, Strings, User Input

AP Computer Science Static Methods, Strings, User Input AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because

More information

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. JAVA TYPES BASIC DATA TYPES GENERAL Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type

More information

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014

Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014 German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Ahmed Gamal Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014

More information

Branching. We ll continue to look at the basics of writing C++ programs including. Overview

Branching. We ll continue to look at the basics of writing C++ programs including. Overview Branching Overview We ll continue to look at the basics of writing C++ programs including Boolean Expressions (need to know this before we can using branching and looping!) Branching J.S. Bradbury CSCI

More information

12-6 Write a recursive definition of a valid Java identifier (see chapter 2).

12-6 Write a recursive definition of a valid Java identifier (see chapter 2). CHAPTER 12 Recursion Recursion is a powerful programming technique that is often difficult for students to understand. The challenge is explaining recursion in a way that is already natural to the student.

More information

A C# program structure About variables Predefined Data Types Flow Control Enumerations Arrays Namespaces The Main() method. Console IO Comments

A C# program structure About variables Predefined Data Types Flow Control Enumerations Arrays Namespaces The Main() method. Console IO Comments Basics of C# What are we going to study? A C# program structure About variables Predefined Data Types Flow Control Enumerations Arrays Namespaces The Main() method Compilation of C# program Console IO

More information

Chapter 4 C Program Control

Chapter 4 C Program Control Chapter 4 C Program Control Objectives of this chapter: Repetitions will be considered in greater detail for.. repetition do while repetition Also multiple selection switch case statement will be learned.

More information

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go Debugging ESE112 Java Programming: API, Psuedo-Code, Scope It is highly unlikely that you will write code that will work on the first go Bugs or errors Syntax Fixable if you learn to read compiler error

More information

TRUE / FALSE MULTIPLE CHOICE

TRUE / FALSE MULTIPLE CHOICE CS 111 Exam 3 FORM A TRUE / FALSE 1. If you write a tostring method for a class, it can be invoked automatically to output the string generated by that method. T 2. You can change the contents of a String

More information

1.2 Built-in Types of Data

1.2 Built-in Types of Data 1.2 Built-in Types of Data Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 1/29/11 6:40 AM! Built-in Data Types Data type. A set

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

CSCE 111 Exam 1 TRUE/FALSE

CSCE 111 Exam 1 TRUE/FALSE CSCE 111 Exam 1 FORM B TRUE/FALSE 1. Java runs differently on different CPU architectures. F 2. A declared variable is always visible to the entire method in which it is declared. F 3. Because the operator

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class

Problem 1. CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class CS 61b Summer 2005 Homework #2 Due July 5th at the beginning of class This homework is to be done individually. You may, of course, ask your fellow classmates for help if you have trouble editing files,

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

JAVA PRIMITIVE DATA TYPE

JAVA PRIMITIVE DATA TYPE JAVA PRIMITIVE DATA TYPE Description Not everything in Java is an object. There is a special group of data types (also known as primitive types) that will be used quite often in programming. For performance

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

Java: Primitive Data Types, Variables and Constants

Java: Primitive Data Types, Variables and Constants Java: Primitive Data Types, Variables and Constants Introduction A primitive data type is a data type provided as a basic building block by a programming language. It is predefined by the programming language

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous

Contents. 9-1 Copyright (c) 1999-2004 N. Afshartous Contents 1. Introduction 2. Types and Variables 3. Statements and Control Flow 4. Reading Input 5. Classes and Objects 6. Arrays 7. Methods 8. Scope and Lifetime 9. Utility classes 10. Introduction to

More information

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011 6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values

More information

Introduction to Java Lecture Notes. Ryan Dougherty redoughe@asu.edu

Introduction to Java Lecture Notes. Ryan Dougherty redoughe@asu.edu 1 Introduction to Java Lecture Notes Ryan Dougherty redoughe@asu.edu Table of Contents 1 Versions....................................................................... 2 2 Introduction...................................................................

More information

A Comparison of the Basic Syntax of Python and Java

A Comparison of the Basic Syntax of Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement CompSci 125 Lecture 08 Chapter 5: Conditional Statements Chapter 4: return Statement Homework Update HW3 Due 9/20 HW4 Due 9/27 Exam-1 10/2 Programming Assignment Update p1: Traffic Applet due Sept 21 (Submit

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

More information

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10) File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The

More information

Chapter 3. Input and output. 3.1 The System class

Chapter 3. Input and output. 3.1 The System class Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

More information

Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004

Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004 Computing Science 114 Solutions to Final Examination Tuesday December 14, 2004 INSTRUCTOR: I. E. LEONARD TIME: 3 HOURS Question 1. [10 = 5 + 5 pts] An operator is said to be overloaded when it is used

More information

Section 6 Spring 2013

Section 6 Spring 2013 Print Your Name You may use one page of hand written notes (both sides) and a dictionary. No i-phones, calculators or any other type of non-organic computer. Do not take this exam if you are sick. Once

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders 1.00 Lecture 1 Course Overview Introduction to Java Reading for next time: Big Java: 1.1-1.7 Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

More information

Intro to Programming in Java Practice Midterm

Intro to Programming in Java Practice Midterm 600.107 Intro to Programming in Java Practice Midterm This test is closed book/notes. SHORT ANSWER SECTION [18 points total] 1) TRUE/FALSE - Please circle your choice: Tr for true, Fa for false. [1 point

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with the basic components of a C++ program,

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Java Names and Variables. GEEN163 Introduction to Computer Programming

Java Names and Variables. GEEN163 Introduction to Computer Programming Java Names and Variables GEEN163 Introduction to Computer Programming What s in a name? That which we call a rose by any other name would smell as sweet. William Shakespeare Clickers Clicking will be required

More information

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006

Basic C Syntax. Comp-206 : Introduction to Software Systems Lecture 10. Alexandre Denault Computer Science McGill University Fall 2006 Basic C Syntax Comp-206 : Introduction to Software Systems Lecture 10 Alexandre Denault Computer Science McGill University Fall 2006 Next Week I'm away for the week. I'll still check my mails though. No

More information

Unit 2: Libraries, Packages, Components, Types, and Variables

Unit 2: Libraries, Packages, Components, Types, and Variables Unit 2: Libraries, Packages, Components, Types, and Variables Preview of Coming Attractions In this unit be sure to look for different types of libraries packages import command primitive types and component

More information

5 Let s all move one place on. Lewis Carroll

5 Let s all move one place on. Lewis Carroll Control Statements: Part 2, Solutions 5 Let s all move one place on Lewis Carroll The wheel is come full circle William Shakespeare How many apples fell on Newton s head before he took the hint! Robert

More information

Using Files as Input/Output in Java 5.0 Applications

Using Files as Input/Output in Java 5.0 Applications Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead

More information

6.092: Introduction to Java. Lecture 1: Types, Variables, Methods

6.092: Introduction to Java. Lecture 1: Types, Variables, Methods 6.092: Introduction to Java Lecture 1: Types, Variables, Methods Outline Intro to Java Types and variables Operators Methods The Computer Memory Central Processing Unit (CPU) Input/Output (IO) Devices

More information

A Quick and Dirty Overview of Java and. Java Programming

A Quick and Dirty Overview of Java and. Java Programming Department of Computer Science New Mexico State University. CS 272 Fall 2004 A Quick and Dirty Overview of Java and.......... Java Programming Enrico Pontelli and Karen Villaverde . Introduction Objectives

More information

CS 101: Practice Questions for Test 2 SOLUTIONS

CS 101: Practice Questions for Test 2 SOLUTIONS CS 101: Practice Questions for Test 2 SOLUTIONS 1. Write a Java application which prompts the user to enter integers from the screen until the end of file character is entered, computes the sum of the

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print

More information

Q1. For the following grammar: S a S b c E E d f E a

Q1. For the following grammar: S a S b c E E d f E a Chapter 3 (3.1 3.3) Describing Syntax and Semantics Chapter 4 Lexical and Syntax Analysis Chapter 5 Names, Binding, Type Checking and Scopes Chapter 6 Data Types Chapter 7 Expressions and Assignment Statements

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

What does the following code print? (Assume the program compiles without error). Trick question! Note the semicolon at the end of the second line.

What does the following code print? (Assume the program compiles without error). Trick question! Note the semicolon at the end of the second line. All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

Program Elements. Notes. Exercises CHAPTER 3

Program Elements. Notes. Exercises CHAPTER 3 CHAPTER 3 Program Elements Notes Chapter 3 introduces the program elements that are the underlying constructs used inside an object to define the services it contributes to a program. Without these constructs,

More information

Unit 6. Loop statements

Unit 6. Loop statements Unit 6 Loop statements Summary Repetition of statements The while statement Input loop Loop schemes The for statement The do statement Nested loops Flow control statements 6.1 Statements in Java Till now

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables CMSC 131 - Lecture Outlines - set

More information

int w = (x + x)*y - y; System.out.println("The value of w is " + w); z = w + 3; System.out.println("The value of z is now " + z);

int w = (x + x)*y - y; System.out.println(The value of w is  + w); z = w + 3; System.out.println(The value of z is now  + z); MIT AITI Mobile Application Development in Java Lab 02: Java Basics Instructions on how to submit Lab 2 will be presented on the screen. Please follow instructions and if they are unclear, please feel

More information

C Programming Dr. Hasan Demirel

C Programming Dr. Hasan Demirel C How to Program, H. M. Deitel and P. J. Deitel, Prentice Hall, 5 th edition (3 rd edition or above is also OK). Introduction to C Programming Dr. Hasan Demirel Programming Languages There are three types

More information

Flow of Control. Conditional Statements. Boolean Expressions. CMPT 125: Lecture 4 Conditionals and Loops

Flow of Control. Conditional Statements. Boolean Expressions. CMPT 125: Lecture 4 Conditionals and Loops Flow of Control CMPT 125: Lecture 4 Conditionals and Loops Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 17, 2009 The order in which statements are executed

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

More information

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program. Software Testing Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program. Testing can only reveal the presence of errors and not the

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I

More information

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer

More information

FORM 1 (Please put your name, section # (10am- 001/2pm-002, and form # on the scantron!!!!) CS 161 Exam I:

FORM 1 (Please put your name, section # (10am- 001/2pm-002, and form # on the scantron!!!!) CS 161 Exam I: FORM 1 (Please put your name, section # (10am- 001/2pm-002, and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The following statement is legal: cout >> Hello, my name is

More information