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

Save this PDF as:
 WORD  PNG  TXT  JPG

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

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

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

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

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

Chapter 2 Elementary Programming

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

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

Input, Process, Output

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

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

Lesson 2C More Operations. By John B. Owen All rights reserved 2011, revised 2015

Lesson 2C More Operations. By John B. Owen All rights reserved 2011, revised 2015 Lesson 2C More Operations By John B. Owen All rights reserved 2011, revised 2015 Table of Contents Objectives Reassignment of variables Operation shortcuts Type casting with primitives String conversion

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

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

MAT 2170: Laboratory 3

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,

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

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

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

More information

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

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

More information

Some Scanner Class Methods

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

More information

JAVA ARRAY EXAMPLE PDF

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

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

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

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

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

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

More information

Object-Oriented Programming in Java

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

More information

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

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

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

Java How to Program, 9/e

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

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

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

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

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

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

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

More information

Basics of Java Programming Input and the Scanner class

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/

More information

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

CS 106 Introduction to Computer Science I

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

More information

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?

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

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html 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

More information

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

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

More information

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

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

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

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

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

More information

Java Libraries and Methods

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

More information

Lab 5: Bank Account. Defining objects & classes

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

More information

Lecture 3. Using Classes and Objects

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

More information

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

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

6.1. Example: A Tip Calculator 6-1

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

More information

Introduction to Programming

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

More information

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

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

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

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

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

[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

More information

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in), 1);

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in), 1); 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.

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

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

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

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

More information

Software and Programming 1

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

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

Comp 248 Introduction to Programming

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

More information

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

More information

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

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

More information

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

More information

Building Java Programs

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.

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

Table 1. Methods in the Math Class

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;

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

(Eng. Hayam Reda Seireg) Sheet Java

(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

More information

Primitive Data Types Summer 2010 Margaret Reid-Miller

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

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

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

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

More information

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. 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:

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

Programmierpraktikum

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

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

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

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

More information

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

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 information

More on Objects and Classes

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

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

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

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

More information

BITG 1113: Problem Solving

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

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

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

Visit us at www.apluscompsci.com

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

More information

Using Classes and Objects

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

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

Chapter One Introduction to Programming

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

More information

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? 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();

More information

A Rudimentary Intro to C programming

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

More information

Java CPD (I) Frans Coenen Department of Computer Science

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

More information

Topic: 1 - Understanding Addition and Subtraction

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

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

CHAPTER. Programming Building Blocks Java Basics

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

More information

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

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

More information

Activity 2: Arithmetic

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

More information

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

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

More information

Arrays in Java. Working with Arrays

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

More information

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

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

More information

Overview of a C Program

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

More information

Dept. of CSE, IIT KGP

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

More information

Chapter 4 Operators & Arithmetic

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)

More information

If you needed to buy the following items, how many different combinations of coins can you make to equal the total amount?

If you needed to buy the following items, how many different combinations of coins can you make to equal the total amount? If you needed to buy the following items, how many different combinations of coins can you make to equal the total amount? (5 price tags are shown with the following prices: 10 cents, 12 cents, 3 cents,

More information

Composing and Decomposing Whole Numbers

Composing and Decomposing Whole Numbers Grade 2 Mathematics, Quarter 1, Unit 1.1 Composing and Decomposing Whole Numbers Overview Number of instructional days: 10 (1 day = 45 60 minutes) Content to be learned Demonstrate understanding of mathematical

More information