# Introduction to Computer Science Unit 2. Notes

Size: px
Start display at page:

Transcription

1 Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and use flow charts evaluate and use Boolean expressions create and use if and if-else statements use the && (AND) and ( OR ) operators use some methods of the Math class. Compiling Code in Java A compiler is a program that translates code to machine language that the central processing unit (the computer's "brain") can understand. In many languages, the source code must be customized for different operating systems and then compiled for certain types of processors. Java works as follows: 1. Java Compiler PC JVM Mac JVM Linux JVM machine language machine language machine language Page 1

2 Boolean Expressions A Boolean expression is an expression that is either or. For example: x >= 8 The above expression compares x to 8. If x is greater than or equal to 8, then the expression is. Otherwise the expression is. Java uses 6 relational operators in its Boolean expressions. 1. If x is an int with a value of 12, what is the value of this expression? 2. If num is an int with a value of 22, what is the value of this expression? 3. If y is an int with a value of 7, what is the value of this expression? x > 10 num == <= y Boolean expressions can be manipulated the same way inequalities in math can be manipulated to produce equivalent expressions. x > * x Rewrite the expression so that all x terms are combined on the left and the coefficient is Are the two expressions equivalent? 5. Are the two expressions equivalent? 6. Are the two expressions equivalent? num <= k k <= num h!= 20 20!= h 20 - y > 5 y < 15 Page 2

3 The if and if-else Statements These statements are sometimes called control statements because they control the flow of the program. Some texts refer to them as conditionals because they represent a condition that may be or. Flowchart Java Code x > 8 x = x + 2 n 5 n = n - 1 n = 3 * n Logical Operators. More complicated Boolean expressions can be composed through the use of logical operators such as AND and OR. The following table shows how certain expressions can be written. English Mathematically Java If the number is greater than 0 and less than or equal to 5. If the number is less than 12 or greater than 65 Page 3

4 Example. Complete the code to the right based on the flowchart below. k++ k = k < k < 7 k = k - 3 k 5 display k k-- k = 2 * k import java.util.scanner; public class Example { public static void main(string[] args) { Scanner x = new Scanner( System.in ); System.out.print("Enter an integer "); int k = x.nextint(); The Math Class. The Math Class contains a collection of standard math functions. Here are some examples on how to use them. To take the square root of a number: double a = Math.sqrt( 16 ); a = Math.sqrt( a ); To raise a number to nth power: double b = Math.pow( 2, 3 ); double c = Math.pow( b, 2.0 ); // a equals // a equals // equivalent to // c equals The sqrt and pow methods always return a Note: to square a number you can always multiply it by itself. int e = 7; int f = e * e; // or int f = (int) Math.pow( e, 2 ); Page 4

5 Find the absolute value: int x = Math.abs( -5 ); // if the argument is an int, the method returns an int double y = Math.abs( -7.3 ); // if the argument is a double, the method returns a double To generate a random decimal between 0 (inclusive) and 1 (exclusive): double g = Math.random(); // double h = 5 * Math.random(); // 1. a is a random decimal within these limits a < double a = 8 * Math.random(); 2. b is a random decimal within these limits b < double b = 10 * Math.random() - 3; To generate a random integer from min (inclusive) and max (inclusive), use the following formula: int num = (int) ( range * Math.random() ) + min; // where range = max min + 1 For example, to generate a random integer between 3 and 6: int num = (int) ( 4 * Math.random() ) + 3; // num is equal to 3, 4, 5, or 6 3. c is a random integer within these limits c int c = (int)( 12 * Math.random() ); 4. d is a random integer within these limits d int d = (int)( 3 * Math.random() ) + 2; 5. e is a random integer within these limits e int e = (int)( 7 * Math.random() ) - 1; Page 5

6 if-else if Statements. The basic if - else structure can be expanded to handle multiple conditionals through the use of else-if statements. For example, if you want to determine if a grade is an A, B, C, D, or E, a simple if - else statement won't work. Flowchart Java Code 0 age<13 age<20 age<120 print "???" print "child" print "teen" print "adult" done get cost get id cost > 100 id = 13 print cost reduce cost by 10% reduce cost by 5% import java.util.scanner; public class Example { public static void main(string[] args) { Scanner sc = new Scanner( System.in ); System.out.print("Enter cost "); double cost = sc.nextdouble(); System.out.print("Enter id "); int id = sc.nextint(); IMPORTANT. Page 6

### Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

### AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

### Introduction to Computer Science Unit 2. Exercises

Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the

### The Math Class. Using various math class methods. Formatting the values.

The Math Class Using various math class methods. Formatting the values. The Math class is used for mathematical operations; in our case some of its functions will be used. In order to use the Math class,

### AP Computer Science Unit 1. Programs

AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated

### Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Programming 2 Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent information Input can receive information

### Java Classes: Math, Integer A C S L E C T U R E 8

Java Classes: Math, Integer A C S - 1903 L E C T U R E 8 Math class Math class is a utility class You cannot create an instance of Math All references to constants and methods will use the prefix Math.

### To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug,

1 To define methods, invoke methods, and pass arguments to a method ( 5.2-5.5). To develop reusable code that is modular, easy-toread, easy-to-debug, and easy-to-maintain. ( 5.6). To use method overloading

### 4. Java Project Design, Input Methods

4-1 4. Java Project Design, Input Methods Review and Preview You should now be fairly comfortable with creating, compiling and running simple Java projects. In this class, we continue learning new Java

### Midterm Examination (MTA)

M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and

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

AP Computer Science Java Mr. Clausen Program 6A, 6B Program 6A LastNameFirstNameP6A (Quadratic Formula: 50 points) (Including complex or irrational roots) Write a program that begins by explaining the

### Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this

### CS110: PROGRAMMING LANGUAGE I

CS110: PROGRAMMING LANGUAGE I Computer Science Department Lecture 8: Methods Lecture Contents: 2 Introduction Program modules in java Defining Methods Calling Methods Scope of local variables Passing Parameters

### Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Chapter 4 Lab Loops and Files Lab Objectives Be able to convert an algorithm using control structures into Java Be able to write a while loop Be able to write an do-while loop Be able to write a for loop

### Important Java terminology

1 Important Java terminology The information we manage in a Java program is either represented as primitive data or as objects. Primitive data פרימיטיביים) (נתונים include common, fundamental values as

### AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education

AP Computer Science Return values, Math, and double Distance between points Write a method that given x and y coordinates for two points prints the distance between them If you can t do all of it, pseudocode?

### Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Methods

WIT COMP1000 Methods Methods Programs can be logically broken down into a set of tasks Example from horoscope assignment:» Get input (month, day) from user» Determine astrological sign based on inputs

### Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:

كلية الحاسبات وتقنية المعلوما Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: October 18, 2015 Student Name: Student ID: Total Marks: 45 Obtained Marks: Instructions: Do not open this

### Objectives of CS 230. Java portability. Why ADTs? 8/18/14

http://cs.wellesley.edu/~cs230 Objectives of CS 230 Teach main ideas of programming Data abstraction Modularity Performance analysis Basic abstract data types (ADTs) Make you a more competent programmer

### Practice Midterm 1 Answer Key

CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages

### Using API in Java. EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG

Using API in Java EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Understand: Self-Exploration of Java API Method Signature Parameters vs. Arguments Non-Static Methods

### 2.2 - Making Decisions

2.2 - Making Decisions So far we have only made programs that execute the statements in order, starting with the statements at the top of the screen and moving down. However, you can write programs that

### Practice Midterm 1. Problem Points Score TOTAL 50

CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the

### NATIONAL UNIVERSITY OF SINGAPORE

NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING TERM TEST #1 Semester 1 AY2006/2007 CS1101X/Y/Z PROGRAMMING METHODOLOGY 16 September 2006 Time Allowed: 60 Minutes INSTRUCTIONS 1. This question paper

### Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

### Activity 4: Methods. Content Learning Objectives. Process Skill Goals

Activity 4: Methods Java programs are organized into classes, each of which has one or more methods, each of which has one or more statements. Writing methods allows you to break down a complex program

### C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

### CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise

### Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

### Computer Programming I - Unit 2 Lecture 1 of 13

1 of 13 Precedence, Mixed Expressions, Math Methods, and Output Fmatting I. Precedence Rules - der of operations Introduction example: 4 + 2 X 3 =? A) Parenthesis, Division Multiplication (from left to

### Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 5 Methods 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Problem int sum = 0; for (int i = 1; i

### M e t h o d s a n d P a r a m e t e r s

M e t h o d s a n d P a r a m e t e r s Objective #1: Call methods. Methods are reusable sections of code that perform actions. Many methods come from classes that are built into the Java language. For

### JAVA PROGRAMMING (340)

Page 1 of 8 JAVA PROGRAMMING (340) REGIONAL 2016 Production Portion: Program 1: Base K Addition (335 points) TOTAL POINTS (335 points) Judge/Graders: Please double check and verify all scores and answer

### What did we talk about last time? Examples switch statements

Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation

### Supplementary Test 1

Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Supplementary Test 1 Question

### CMPS 11 Introduction to Programming Midterm 1 Review Problems

CMPS 11 Introduction to Programming Midterm 1 Review Problems Note: The necessary material for some of these problems may not have been covered by end of class on Monday, the lecture before the exam. If

### CS141 Programming Assignment #6

CS141 Programming Assignment #6 Due Sunday, Nov 18th. 1) Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2 1

### Object Oriented Programming. Java-Lecture 6 - Arrays

Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types

### CIS133J. Working with Numbers in Java

CIS133J Working with Numbers in Java Contents: Using variables with integral numbers Using variables with floating point numbers How to declare integral variables How to declare floating point variables

### Chapter 6 Methods. Dr. Hikmat Jaber

Chapter 6 Methods Dr. Hikmat Jaber 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Problem int sum = 0; for (int i = 1; i

### CSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:

Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this

### CT 229 Java Syntax Continued

CT 229 Java Syntax Continued 06/10/2006 CT229 Lab Assignments Due Date for current lab assignment : Oct 8 th Before submission make sure that the name of each.java file matches the name given in the assignment

### Object-Based Programming. Programming with Objects

ITEC1620 Object-Based Programming g Lecture 8 Programming with Objects Review Sequence, Branching, Looping Primitive datatypes Mathematical operations Four-function calculator Scientific calculator Don

### Chapter 5 Methods. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 5 Methods 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Problem int sum = 0; for (int i = 1; i

### The Math Class (Outsource: Math Class Supplement) Random Numbers. Lab 06 Math Class

The (Outsource: Supplement) The includes a number of constants and methods you can use to perform common mathematical functions. A commonly used constant found in the Math class is Math.PI which is defined

www.thestudycampus.com Methods Let s imagine an automobile factory. When an automobile is manufactured, it is not made from basic raw materials; it is put together from previously manufactured parts. Some

### Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators

Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY Arithmetic Operators There are four basic arithmetic operations: OPERATOR USE DESCRIPTION + op1 + op2 Adds op1 and op2 - op1 + op2 Subtracts

### AP Computer Science A. Return values

AP Computer Science A Return values Distance between points Write a method that given x and y coordinates for two points prints the distance between them Pseudocode? Java's Math class Method name Math.abs(value)

### Formatting Output & Enumerated Types & Wrapper Classes

Formatting Output & Enumerated Types & Wrapper Classes Quick review of last lecture September 8, 2006 ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev

### CS111: PROGRAMMING LANGUAGE II

1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables

### M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case

### Lecture 5: Methods CS2301

Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

### Warm up Exercise. What are the types and values of the following expressions: * (3 + 1) 3 / / 2.0 (int)1.0 / 2

Warm up Exercise What are the types and values of the following expressions: 3.0+4 * (3 + 1) 3 / 2 + 1.0 1.0 / 2.0 (int)1.0 / 2 COMP-202 - Programming Basics 1 Warm up Exercise What are the types and values

### Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

CS256 Computer Science I Kevin Sahr, PhD Lecture 25: Miscellaneous 1 main Method Arguments recall the method header of the main method note the argument list public static void main (String [] args) we

### ICSE Class 10 Computer Applications ( Java ) 2014 Solved Question Paper

1 of 10 05-11-015 16:1 ICSE J Java for Class X Computer Applications ICSE Class 10 Computer Applications ( Java ) 014 Solved Question Paper ICSE Question Paper 014 (Solved) Computer Applications Class

### Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

Java Tutorial Ashkan Taslimi Saarland University Tutorial 3 September 6, 2011 1 Outline Tutorial 2 Review Access Level Modifiers Methods Selection Statements 2 Review Programming Style and Documentation

### Programming with Java

Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

### Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac

### Chapter 5 Methods / Functions

Chapter 5 Methods / Functions 1 Motivations A method is a construct for grouping statements together to perform a function. Using a method, you can write the code once for performing the function in a

### More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input

### Methods CSC 121 Spring 2017 Howard Rosenthal

Methods CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods

### Building Java Programs

Building Java Programs Chapter 3 Lecture 7: Return values, Math, and casting reading: 3.2, 2.1-2.2 (Slides adapted from Stuart Reges, Hélène Martin, and Marty Stepp) Copyright 2011 by Pearson Education

### Welcome to the Primitives and Expressions Lab!

Welcome to the Primitives and Expressions Lab! Learning Outcomes By the end of this lab: 1. Be able to define chapter 2 terms. 2. Describe declarations, variables, literals and constants for primitive

### Data Structure and Programming Languages

204700 Data Structure and Programming Languages Jakarin Chawachat From: http://ocw.mit.edu/courses/electrical-engineering-and-computerscience/6-092-introduction-to-programming-in-java-january-iap-2010/index.htm

### 12. Numbers. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

12. Numbers Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Numeric Type Conversions Math Class References Numeric Type Conversions Numeric Data Types (Review) Numeric Type Conversions Consider

### CSC 1051 Data Structures and Algorithms I

Repetition CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this

### C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: User-Defined Functions I

C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 6: User-Defined Functions I In this chapter, you will: Objectives Learn about standard (predefined) functions and discover

### Lecture 6: While Loops and the Math Class

Lecture 6: While Loops and the Math Class Building Java Programs: A Back to Basic Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. while loops 2 Categories of loops

### static int min(int a, int b) Returns the smaller of two int values. static double pow(double a,

The (Outsource: Supplement) The includes a number of constants and methods you can use to perform common mathematical functions. A commonly used constant found in the Math class is Math.PI which is defined

### CSE Module 1. A Programming Primer 1/23/19 CSE 1321 MODULE 1 1

CSE 1321 - Module 1 A Programming Primer 1/23/19 CSE 1321 MODULE 1 1 Motivation You re going to learn: The skeleton Printing Declaring variables Reading user input Doing basic calculations You ll have

### Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 5 Methods rights reserved. 0132130807 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. rights reserved. 0132130807 2 1 Problem int sum =

### Pace University. Fundamental Concepts of CS121 1

Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

### Topics. Chapter 5. Equality Operators

Topics Chapter 5 Flow of Control Part 1: Selection Forming Conditions if/ Statements Comparing Floating-Point Numbers Comparing Objects The equals Method String Comparison Methods The Conditional Operator

### COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz

COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about

### Chapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Motivations If you assigned a negative value for radius

### double float char In a method: final typename variablename = expression ;

Chapter 4 Fundamental Data Types The Plan For Today Return Chapter 3 Assignment/Exam Corrections Chapter 4 4.4: Arithmetic Operations and Mathematical Functions 4.5: Calling Static Methods 4.6: Strings

### Java Reference Card. 1. Classes. 2. Methods. 3. Conditionals. 4. Operators

Java Reference Card 1. Classes The following is an example of a main class: public class Calculator { public static void main(string[] args) { and the following is an example of a utility class (with no

### Building Java Programs

Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2, 2.1-2.2 Java's Math class Method name Math.abs(value) Math.ceil(value) Math.floor(value) Description absolute

### A Foundation for Programming

2.1 Functions A Foundation for Programming any program you might want to write objects functions and modules build bigger programs and reuse code graphics, sound, and image I/O arrays conditionals and

### CS 200 Using Objects. Jim Williams, PhD

CS 200 Using Objects Jim Williams, PhD This Week Notes By Friday Exam Conflict and Accommodations Install Eclipse (version 8) Help Queue Team Lab 2 Chap 2 Programs (P2): Due Thursday Hours Spent Week?

### CSC 1051 Algorithms and Data Structures I. Midterm Examination October 6, Name:

CSC 1051 Algorithms and Data Structures I Midterm Examination October 6, 2016 Name: Question Value Score 1 20 2 20 3 20 4 20 5 20 TOTAL 100 Please answer questions in the spaces provided. If you make a

### JAVA OPERATORS GENERAL

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

### Advanced Java Concept Unit 1. Mostly Review

Advanced Java Concept Unit 1. Mostly Review Program 1. Create a class that has only a main method. In the main method create an ArrayList of Integers (remember the import statement). Add 10 random integers

### Selection and Repetition Revisited

Selection and Repetition Revisited CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

### AP Computer Science A Unit 2. Exercises

AP Computer Science A Unit 2. Exercises A common standard is 24-bit color where 8 bits are used to represent the amount of red light, 8 bits for green light, and 8 bits for blue light. It is the combination

### Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void

### Oct Decision Structures cont d

Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements

### Chapter 5 Methods. Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk

Chapter 5 Methods Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Introducing Methods A method is a collection of statements that

### CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

CSC 1051 Algorithms and Data Structures I Midterm Examination February 25, 2016 Name: KEY A Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in

### Mathematical Functions, Characters, and Strings. CSE 114, Computer Science 1 Stony Brook University

Mathematical Functions, Characters, and Strings CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Static methods Remember the main method header? public static void

### JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA

### Chapter 7. Iteration. 7.1 Multiple assignment

Chapter 7 Iteration 7.1 Multiple assignment You can make more than one assignment to the same variable; effect is to replace the old value with the new. int bob = 5; System.out.print(bob); bob = 7; System.out.println(bob);

### Java I/O and Control Structures

Java I/O and Control Structures CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying

### CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 7&8: Methods Lecture Contents What is a method? Static methods Declaring and using methods Parameters Scope of declaration Overloading

### Chapter 3. Selections

Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of

CS 101, Prof. Loftin: Final Exam, May 11, 2009 Name: All your work should be done on the pages provided. Scratch paper is available, but you should present everything which is to be graded on the pages

### Java I/O and Control Structures Algorithms in everyday life

Introduction Java I/O and Control Structures Algorithms in everyday life CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Source: http://xkcd.com/627/

### Building Java Programs

Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2, 2.1-2.2 Copyright 2011 by Pearson Education 2 Method name Math.abs(value) Math.ceil(value) Math.floor(value)