# Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

 To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
Save this PDF as:

Size: px
Start display at page:

Download "Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard"

## Transcription

1 INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard String indata; // String variable } } System.out.println("Enter the data:"); indata = sc.nextline(); // read a line from scanner System.out.println("You entered: " + indata ); I/O Example Using keyboard input for Integers import java.util.scanner; class EchoSquare{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard int num, square; // declare two int variables System.out.println("Enter an integer:"); num = sc.nextint(); // read an int from scanner square = num * num ; // compute the square } } System.out.println("The square of " + num + " is " + square);

2 Exercise 11 Area of a Circle Write a program that calculates the area of a circle from its radius. The radius will be an integer read in from the keyboard. The user dialog will look like this: D:\users\default>java CircleArea Input the radius: 3 The radius is: 3 The area is: You will need to use the constant PI which you get by using Math.PI

3 Exercise 12 Cents to Dollars Write a program that reads in a number of cents. The program will write out the number of dollars and cents, like this: D:\users\default>java Dollars Input the cents: 324 That is 3 dollars and 24 cents. (For this program you will use integer arithmetic and will need to avoid floating point arithmetic. Review the integer remainder operator % if you are unsure how to proceed.)

4 Exercise 13 Correct Change When cashiers in a store give you change they try first to "fit" dollars into the amount you get back, then try to "fit" quarters (25 cent coins) into what is left over, they try to "fit" dimes (10 cent coins) into what is now left over, then try to "fit" nickels (5 cent coins) into what is left, and finally are left with a few odd cents. For example, say that your change is 163 cents: One dollar fits into 163, leaving 63 cents. Two quarters fit into 63 cents, leaving 13 cents. One dime fits into 13 cents, leaving 3 cents. No nickels are needed. Three cents are left. Your change is : 1 dollar, two quarters, one dime, and three cents. Write a program that reads change due to a user (in cents) and writes out how many dollars, quarters, dimes, nickels, and pennies she is due. All variables and all math in this program will be integers. If you are stuck, it will help to do an example problem with paper and pencil.

5 Exercise 14 Ohm's Law Ohm's law relates the resistance of a electrical device (like a heater) to the electric current flowing through the device and the voltage applied to it. The law is: I = V/R Here, V is the voltage (measured in volts), I is the current (measured in amps), and R is the resistance (measured in ohms.) Write a program that asks the user for the voltage and the resistance of a device. The program will then write out the current flowing through it. Use floating point math. Since V and R are integers (converted from user input) you must use a trick to do floating point division. Change the equation to this: I = (V + 0.0)/R The math inside parentheses is done first. So V is done first, and since 0.0 is floating point, so will be the result.

6 FLOATING POINT INPUT Exercise 15 Power Costing Write a program that calculates the annual cost of running an appliance. The program will ask the user for the cost per kilowatt-hour and the number of kilowatt-hours the appliance uses in a year: Enter cost per kilowatt-hour in cents 8.42 Enter kilowatt-hours used per year 653 Annual cost:

7 Exercise 16 Another Brick in the Wall When a brick is dropped from a tower, it falls faster and faster until it hits the earth. The speed v is given by v = (1/2) g t 2 Here v is the speed in feet per second, t is the time in seconds, and g is Write a program that asks the user for the number of seconds and then prints out the speed. Enter the number of seconds 5.4 Speed of the brick: feet per second One hundred miles per hour is feet per second. Use your program to determine approximately how long it takes the brick to reach that speed.

8 Exercise 17 Logarithms The base 2 logarithm of a number is defined by: log 2 X = n if 2 n = X For example log 2 32 = 5, because 2 5 = 32 log = 10, because 2 10 = 1024 Write a program that inputs a number and outputs its base 2 logarithm. Use floating point input. This problem would be easy, but the Math package does not have a base 2 logarithm method. Instead you have to do this: log 2 X = (log e X) / (log e 2) Here, log e X is the natural logarithm of X. Use this function in the Java Math package: Math.log( X ) When you use this, X must be a double. Write the program so that the user can enter floating point numbers. Enter a double: Base 2 log of is

9 Exercise 18 Harmonic Mean The harmonic mean of two numbers is given by: H = 2 / ( 1/X + 1/Y ) This is sometimes more useful than the more usual average of two numbers. Write a program that inputs two numbers (as floating point) and writes out both the usual average (the arithmetic mean) and the harmonic mean. Enter X: 12 Enter Y: 16 Arithmetic mean: 14.0 Harmonic mean:

### 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

### 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

### 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

### 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

### Chapter 2 Elementary Programming

Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

### 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

### Input, Process, Output

Input, Process, Output Chapter 1 1 Introduction A computer program is a solution to a problem Most useful computer programs do at least 3 things: Input input data process data output resulting information

### 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

### 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

### 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

### MAT 2170: Laboratory 3

MAT 2170: Laboratory 3 Key Concepts The purpose of this lab is to familiarize you with arithmetic expressions in Java. 1. Primitive Data Types int and double 2. Operations involving primitive data types,

### 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

### THE JAVA API. Some of the Java API Packages Package Theme Some Classes Within It. Classes that provide helpful utilities

THE JAVA API The Java API which stands for Application Programming Interface is a repository of prewritten classes provided by the creators of Java to enhance its usefulness. There are classes for creating

### CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

### Some Scanner Class Methods

Keyboard Input Scanner, Documentation, Style Java 5.0 has reasonable facilities for handling keyboard input. These facilities are provided by the Scanner class in the java.util package. A package is a

### JAVA ARRAY EXAMPLE PDF

JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1 Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static

### 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 ******

### 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

### 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

### Motivations. Chapter 2: Elementary Programming. Introducing Programming with an Example 7/18/16. CS1: Java Programming Colorado State University

Chapter 2: Elementary Programming CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox Motivations In the preceding chapter, you learned how to

### Object-Oriented Programming in Java

CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

### Programming Fundamentals I CS 110, Central Washington University. November 2015

Programming Fundamentals I CS 110, Central Washington University November 2015 Next homework, #4, was due tonight! Lab 6 is due on the 4 th of November Final project description + pseudocode are due 4th

### 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

### Java How to Program, 9/e

Java How to Program, 9/e Education, Inc. All Rights Reserved. 1 Any computing problem can be solved by executing a series of actions in a specific order. An algorithm is a procedure for solving a problem

### 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

### PROGRAMMING REFRESHER MODULE. Delivered by Ana Cavalcanti and Alvaro Miyazawa Prepared by Dr Lilian Blot

PROGRAMMING REFRESHER MODULE Delivered by Ana Cavalcanti and Alvaro Miyazawa Prepared by Dr Lilian Blot The Rules Everything in PREF (Week 1) is optional. From week 2 of APRC and JAPC, we assume that all

### 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[]

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

### Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

### Basics of Java Programming Input and the Scanner class

Basics of Java Programming Input and the Scanner class CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

### 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)

### CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I 01 / 29 / 2014 Instructor: Michael Eckmann Today s Topics Comments and/or Questions? import user input using JOptionPane user input using Scanner psuedocode import

### I = V/r P = VI. I = P/V = 100 W / 6 V = 16.66 amps. What would happen if you use a 12-volt battery and a 12-volt light bulb to get 100 watts of power?

Volts, Amps and Ohms Measuring Electricity The three most basic units in electricity are voltage (V), current (I) and resistance (r). Voltage is measured in volts, current is measured in amps and resistance

CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

### The following program is aiming to extract from a simple text file an analysis of the content such as:

Text Analyser Aim The following program is aiming to extract from a simple text file an analysis of the content such as: Number of printable characters Number of white spaces Number of vowels Number of

### AP Computer Science Java Mr. Clausen Program 9A, 9B

AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will

### 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

### Fundamentals of Programming. Laboratory 5 Methods. General-purpose and user - defined methods

Fundamentals of Programming Laboratory 5 Methods. General-purpose and user - defined methods What is a method? Block of code that receives its own identifier - i.e. can be executed using its name Different

### Java Libraries and Methods

COMP-202 Java Libraries and Methods COMP-202 - Java Library and Methods, 2013 Jörg Kienzle and others Chapter Outline Using Library Methods Java.Math example Writing your own Methods Void Methods Methods

### Lab 5: Bank Account. Defining objects & classes

Lab 5: Bank Account Defining objects & classes Review: Basic class structure public class ClassName Fields Constructors Methods Three major components of a class: Fields store data for the object to use

### Lecture 3. Using Classes and Objects

Lecture 3 Using Classes and Objects Using Classes and Objects We can create more interesting programs using predefined classes and related objects Chapter 3 focuses on: object creation and object references

### IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

IRA EXAMPLES This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). Definite Counting Loop Example IRA After x Years This first example illustrates

### 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,

### 6.1. Example: A Tip Calculator 6-1

Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for

### Introduction to Programming

Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck

### Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used

### 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

### 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

### [Page 70 (continued)] a. are used to document a program and improve its readability. [Page 71]

[Page 70 (continued)] Exercises 2.7 Discuss the meaning of each of the following objects: a. std::cin b. std::cout 2.8 Fill in the blanks in each of the following: a. are used to document a program and

Keyboard Input Our programs thus far generated data internally, operated on the data, and printed results. A more interesting approach is to engage the user to provide input data on the host system's keyboard.

### 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

### 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

### Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples

Identifiers and Expressions CSE 130: Introduction to C Programming Spring 2005 Punctuation in C Statements are terminated with a ; Groups of statements are enclosed by curly braces: { and } Commas separate

### Software and Programming 1

Software and Programming 1 Lab 3: Strings & Conditional Statements 20 January 2016 SP1-Lab3.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab Objectives This session we are concentrating on Strings and conditional

### 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

### Comp 248 Introduction to Programming

Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been

### Introduction to Java. Module 5: Use of classes and instances. Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Introduction to Java Module 5: Use of classes and instances Prepared by Costantinos Costa for EPL 233 ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1 ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 2 Objective Introduction

### Java : Data types, Identifiers and Operators. Instructor: Nihshanka Debroy

Java : Data types, Identifiers and Operators Instructor: Nihshanka Debroy Java Programs Can use a text editor to type out Java code Save as a file with.java extension (Example: HelloWorld.java) File contains

### 1st Grade Math Standard I Rubric. Number Sense. Score 4 Students show proficiency with numbers beyond 100.

1st Grade Math Standard I Rubric Number Sense Students show proficiency with numbers beyond 100. Students will demonstrate an understanding of number sense by: --counting, reading, and writing whole numbers

### Building Java Programs

Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1-5.2 self-check: #8-17 exercises: #3-6, 10, 12 videos: Ch. 5 #1-2 1 The Random class A Random object generates pseudo-random* numbers.

### 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

### Table 1. Methods in the Math Class

The Math Class It is hard to avoid the Math class in any Java program that requires scientific or other numeric computations. As with the wrapper classes, the Math class is part of the java.lang package;

### 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

### (Eng. Hayam Reda Seireg) Sheet Java

(Eng. Hayam Reda Seireg) Sheet Java 1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long. What changes must be made to the program so it works for a rectangle

### Primitive Data Types Summer 2010 Margaret Reid-Miller

Primitive Data Types 15-110 Summer 2010 Margaret Reid-Miller Data Types Data stored in memory is a string of bits (0 or 1). What does 1000010 mean? 66? 'B'? 9.2E-44? How the computer interprets the string

### 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

### Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

Variables in a programming language Basic Computation (Savitch, Chapter 2) TOPICS Variables and Data Types Expressions and Operators Integers and Real Numbers Characters and Strings Input and Output Variables

### Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:

### 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

### Programmierpraktikum

Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 10/16/2012 09:29 AM Java - A First Glance 2 of 21 10/16/2012 09:29 AM programming languages

### 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

### 6. the result you get when you divide fifteen by four times a number. Hk 2, 105 Written problems

Hk 2, 105 Written problems The simplest written problems just say something about some numbers,and ask what the numbers are. First we need to be able to translate words into algebraic expressions. For

### Lab Installation Directory: If your computer has the standard lab setup, the directories will be something like:

Lab 3: Operators In this lab, you will work with Java operators. Objectives: To learn Java operators Part 0: Getting Started Ask your instructor for the following information: Lab Installation directory:

### More on Objects and Classes

Software and Programming I More on Objects and Classes Roman Kontchakov Birkbeck, University of London Outline Object References Class Variables and Methods Packages Testing a Class Discovering Classes

### 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

### In Java, the symbol + can be used to add numbers or to concatenate strings. This exercise illustrates both uses.

Chapter 2: Data and Expressions Lab Exercises Two Meanings of Plus In Java, the symbol + can be used to add numbers or to concatenate strings. This exercise illustrates both uses. When using a string literal

### BITG 1113: Problem Solving

BITG 1113: Problem Solving 1 Learning Outcomes At the end of this lecture, you should be able to: explain the software development methodology identify basic problem solving techniques describe the steps

### 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,

### 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

### Visit us at www.apluscompsci.com

Visit us at www.apluscompsci.com Full Curriculum Solutions M/C Review Question Banks Live Programming Problems Tons of great content! www.facebook.com/apluscomputerscience Scanner kb = new Scanner(System.in);

### Using Classes and Objects

Chapter 3: Using Classes and Objects Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Using Classes and Objects We can create more interesting programs using predefined

### 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

### Chapter One Introduction to Programming

Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

### Computer & Programming I Quiz #5 Dr. H. Assadipour 1. What is the output of the following program?

Computer & Programming I Quiz #5 Dr. H. Assadipour 1. What is the output of the following program? Driver Program public class ThingTester public static void main (String[] args) Thing one = new Thing();

### A Rudimentary Intro to C programming

A Rudimentary Intro to C programming Wayne Goddard School of Computing, Clemson University, 2008 Part 1: Variables and Data-types 1 Getting Started............................... A1 2 Some Basics.................................

### Java CPD (I) Frans Coenen Department of Computer Science

Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials

### Topic: 1 - Understanding Addition and Subtraction

8 days / September Topic: 1 - Understanding Addition and Subtraction Represent and solve problems involving addition and subtraction. 2.OA.1. Use addition and subtraction within 100 to solve one- and two-step

### 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

### CHAPTER. Programming Building Blocks Java Basics

04387_CH02_Anderson.qxd 12/8/10 1:16 PM Page 41 CHAPTER Programming Building Blocks Java Basics 2 CHAPTER CONTENTS Introduction 2.1 Java Application Structure 2.2 Data Types, Variables, and Constants 2.2.1

### PE1 Worksheet. 3) What are the three control structures for writing an algorithm in pseudocode?

PE1 Worksheet Problem solving 1) What are the four stages of problem solving by programming? What shall be done in each stage? Stage 1: Stage 2: Stage 3: Stage 4: 2) What is the top-down design strategy

### Activity 2: Arithmetic

Activity 2: Arithmetic Now that you ve written a few programs, let s take a step back and discuss how to do basic arithmetic. But first, there s something important to know about why you re working in

### Use Inchworms. Measure each item. inches. inches. Find each item. Estimate the length. Use Inchworms to measure the length. 3. one side of a book

Lesson 1 Measurement and Data Name Use Inchworms. Measure each item. 1. inches 2. Find each item. Estimate the length. Use Inchworms to measure the length. inches 3. one side of a book Estimate: inches

### Arrays in Java. Working with Arrays

Arrays in Java So far we have talked about variables as a storage location for a single value of a particular data type. We can also define a variable in such a way that it can store multiple values. Such

### Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

### Overview of a C Program

Overview of a C Program Programming with C CSCI 112, Spring 2015 Patrick Donnelly Montana State University Programming with C (CSCI 112) Spring 2015 2 / 42 C Language Components Preprocessor Directives

### Dept. of CSE, IIT KGP

Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the

### Chapter 4 Operators & Arithmetic

Chapter 4 Operators & Arithmetic 4-1 Arithmetic in C++ Arithmetic expressions can be made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition)