Programmierpraktikum

Size: px
Start display at page:

Download "Programmierpraktikum"

Transcription

1 Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 22 10/25/ :08 AM

2 Java - Basic Data Types 2 of 22 10/25/ :08 AM

3 primitive data types int, double, char,... are primitive (predefined) data types arbitrary complex data types may be defined by the user String is (however) an object, like everything else Typ Size Domain Example boolean 1 {true, false} short 2 int 4 [ 2 31, ] = long 8 [ 2 63, ] float 4 [ , ] double 8 [ , ] 3 of 22 10/25/ :08 AM

4 short / long for specialized applications only float not used anymore, standard is double for floating point operations 32/64 bits (int/double) used for memory addressing by 32/64 bit processors, memory restrictions 4 of 22 10/25/ :08 AM

5 example: primitive data types casting of one data type to another will be disussed later public class PrimitiveDataTypes { public static void main(string[] args) { // --- pi with double (16 digits) and float (8 digits) // --- Math.PI is a double constant double double_pi = Math.PI; float float_pi = (float)math.pi; // casting double to float System.out.printf("pi with double: %24.20f\n",double_PI); 12. System.out.printf("pi with float: %24.20f\n",float_PI); System.out.printf("%25s ^\n",""); System.out.println(" "); // --- int and long integer numbers int int_int = 1; // pointer // empty line 5 of 22 10/25/ :08 AM

6 18. long long_int = 1; for (int i=0; i<34; i++) { int_int = int_int * 2; long_int = long_int * 2; System.out.printf("i+1, short, int, long: %4d %12d %12d\n", i+1, int_int, long_int); } } 29. } 6 of 22 10/25/ :08 AM

7 strings a string (word) is an aribitrary sequence of characters the String class java.lang.string has many built-in member functions for string manipulation String concatenation with public class ExampleStrings { public static void main(string[] args) { // --- defining and printing // --- touppercase() is a member function of the String class String cdde = "cdde"; System.out.println("abc"); System.out.println(cdde); System.out.println(cdde.toUpperCase()); of 22 10/25/ :08 AM

8 13. // --- String concatenation with '+' 14. System.out.println("abc" + " " + cdde); // --- substring() is a member function of the String class String c = "abc".substring(2,3); String dd = cdde.substring(1,3); System.out.println(" c: " + c); System.out.println("dd: " + dd); // --- valueof() casts numbers into strings System.out.println(String.valueOf(Math.PI)); } // end of ExampleStrings.main() } // end of class ExampleStrings of 22 10/25/ :08 AM

9 casting vs parsing here: conversion of primitive data types and strings later: casting of objects 2. import java.util.*; import java.math.*; public class CastingDemo { public static void main(string args[]) { double rr = Math.random(); String ss = String.valueOf(rr); // converting double into string System.out.println("a random number as a string: " + ss); System.out.printf( " and back: %f\n\n", Double.parseDouble(ss)); // parsing 13. // 14. int ii = (int)(math.random()*100.0); // casting double into int 15. System.out.printf( " random integer and string : %d %s\n", 9 of 22 10/25/ :08 AM

10 16. ii, String.valueOf(ii)); } // end of CastingDemo.main() } // end of CastingDemo 10 of 22 10/25/ :08 AM

11 arrays n-component array int[] array = new int[n]; value of array-component k int b = array[k]; array with predefined values int[] array = {1, 2, 3}; length n of array int b = array.length; multi-dimensional arrays int[][] array = new int[n][m]; 11 of 22 10/25/ :08 AM

12 example: arrays arrays start always with [0] 2. public class ExampleArrays { public static void main(string[] args) { // --- array of integers int[] values = {2, 3, 5, 7, 11, 13}; System.out.println(values[3]); // // --- array of strings String[] colors = {"yellow", "red", "green", "blue"}; colors[0] = "black"; for (int i=0; i<colors.length; i++) System.out.printf("This is color[%d]: %s \n", i, colors[i]); System.out.println(" "); // empty line // --- splitting a string, typically used when reading from file String inputstring = "age height weight"; String[] words = inputstring.split(" "); 12 of 22 10/25/ :08 AM

13 for (int i=0; i<words.length; i++) System.out.printf("This is words[%d]: %s \n", i, words[i]); System.out.println(" "); // empty line // --- array of chars char[] chars = "black sun".tochararray(); for (int i=0; i<chars.length; i++) System.out.printf("This is chars[%d]: %c \n", i, chars[i]); } } 13 of 22 10/25/ :08 AM

14 example: matrices matrix.length: the number of rows matrix[i].length: the number of elements in row[i] the number of elements per row may be variable (ragged matrix) public class ExampleMatrices { public static void main(string[] args) { // --- defining a 3x2 matrix (3 rows and 2 columns) String[][] strmatrix = new String[3][2]; String[] rowzero = { "rowzero[0]", "rowzero[1]"}; String[] rowone = { "rowone[0]", "rowone[1]"}; strmatrix[0] = rowzero; // setting row [0] strmatrix[1] = rowone; // setting row [1] // --- printing matrix // --- note: row[2] is undefined (null) for (int i = 0; i<strmatrix.length; i++) 14 of 22 10/25/ :08 AM

15 for (int j = 0; j<strmatrix[i].length; j++) System.out.printf(" strmatrix[%d][%d]: %s\n", i, j, strmatrix[i][j]); System.out.println(" "); // --- a matrix needs not to be rectangular, may be ragged int[][] intmatrix = new int[3][]; int[] row_0 = {0,1,2,3,4}; int[] row_1 = {5,6,7}; int[] row_2 = {8,9}; intmatrix[0] = row_0; intmatrix[1] = row_1; intmatrix[2] = row_2; // allocate the number of rows for (int i = 0; i<intmatrix.length; i++) { System.out.printf(" strmatrix[%d]:",i); for (int j = 0; j<intmatrix[i].length; j++) System.out.printf(" %d",intmatrix[i][j]); System.out.printf("\n"); } } // end of ExampleMatrices.main() 15 of 22 10/25/ :08 AM

16 38. } // end of class ExampleMatrices 16 of 22 10/25/ :08 AM

17 exercise: matrix operations training suggestion write a code for calculating the scalar product between two vectors and for matrix multiplication n m-matrix int[][] matrix = new int[n][m]; value of M ij matrix[i][j] initialize matrix with predefined values int[][] matrix = new int[][] {{1, 2, 3}, {4, 5, 6}}; write a code for evaluating the trace of a given matrix tr(m) i M ii 17 of 22 10/25/ :08 AM

18 18 of 22 10/25/ :08 AM

19 arithmetic operators assignment and arithmetics Symbol Description Examples = assignment int i=5; + - addition, subtraction int i=5+3; int i=5-3; * / multiplication, integer division int i=5*3; int i=9/3; % modulo int i=14%3; + - unary plus/minus int i=+3; int i=-2; += -= *= /= assignment and operation i += 5; // i = i pre-/postfix increment/decrement i++; // i = i + 1 naming of C++ 19 of 22 10/25/ :08 AM

20 mathematical functions import for basic mathematics import java.lang.math; π e , Euler's number 2. static final double PI; static final double E; absolute value x static int abs(int x); minimum/maximum value 2. static int min(int x, int y); static int max(int x, int y); (arcus-, hyperbolic-) sinus/cosine/tangent static double sin(double x); 20 of 22 10/25/ :08 AM

21 static double cos(double x); static double tan(double x); static double asin(double x); static double acos(double x); static double atan(double x); static double hsin(double x); static double hcos(double x); static double htan(double x); square/cubic root 2. static double sqrt(double x); static double cbrt(double x); exponential e x static double exp(double x); power x y static double pow(double x, double y); logarithm (base e/10) 2. static double log(double a); static double log10(double a); 21 of 22 10/25/ :08 AM

22 round 2. static double round(double a); static long round(double a); 22 of 22 10/25/ :08 AM

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

More information

CS110: PROGRAMMING LANGUAGE I

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

More information

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

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

More information

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

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

More information

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

More information

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

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

More information

Chapter 5 Methods / Functions

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 information

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

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 =

More information

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

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Mathematical Functions Java provides many useful methods in the Math class for performing common mathematical

More information

Expressions and operators

Expressions and operators Mathematical operators and expressions The five basic binary mathematical operators are Operator Operation Example + Addition a = b + c - Subtraction a = b c * Multiplication a = b * c / Division a = b

More information

Chapter 6 Methods. Dr. Hikmat Jaber

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

More information

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

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

More information

JAVA OPERATORS GENERAL

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

More information

DUBLIN CITY UNIVERSITY

DUBLIN CITY UNIVERSITY DUBLIN CITY UNIVERSITY SEMESTER ONE EXAMINATIONS 2007 MODULE: Object Oriented Programming I - EE219 COURSE: B.Eng. in Electronic Engineering B.Eng. in Information Telecommunications Engineering B.Eng.

More information

Chapter 4 Mathematical Functions, Characters, and Strings

Chapter 4 Mathematical Functions, Characters, and Strings Chapter 4 Mathematical Functions, Characters, and Strings Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited 2015 1 Motivations Suppose you need to estimate

More information

COP3502 Programming Fundamentals for CIS Majors 1. Instructor: Parisa Rashidi

COP3502 Programming Fundamentals for CIS Majors 1. Instructor: Parisa Rashidi COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi Chapter 4 Loops for while do-while Last Week Chapter 5 Methods Input arguments Output Overloading Code reusability Scope of

More information

Chapter 5 Methods. Modifier returnvaluetype methodname(list of parameters) { // method body; }

Chapter 5 Methods. Modifier returnvaluetype methodname(list of parameters) { // method body; } Chapter 5 Methods 5.1 Introduction A method is a collection of statements that are grouped together to perform an operation. You will learn how to: o create your own mthods with or without return values,

More information

DUBLIN CITY UNIVERSITY

DUBLIN CITY UNIVERSITY DUBLIN CITY UNIVERSITY REPEAT EXAMINATIONS 2008 MODULE: Object-oriented Programming I - EE219 COURSE: B.Eng. in Electronic Engineering (Year 2 & 3) B.Eng. in Information Telecomms Engineering (Year 2 &

More information

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

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program 1 Why Programming? Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies,

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

1.1 Your First Program! Naive ideal. Natural language instructions.

1.1 Your First Program! Naive ideal. Natural language instructions. Why Programming? Why programming? Need to tell computer what you want it to do. 1.1 Your First Program Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies, subject

More information

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies, subject

More information

Benefits of Methods. Chapter 5 Methods

Benefits of Methods. Chapter 5 Methods Chapter 5 Methods Benefits of Methods Write a method once and reuse it anywhere. Information hiding: hide the implementation from the user Reduce complexity 1 4 Motivating Example Often we need to find

More information

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I

ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I ENGI 1020 - Introduction to Computer Programming M A Y 2 8, 2 0 1 0 R E Z A S H A H I D I Last class Last class we talked about the following topics: Constants Assignment statements Parameters and calling

More information

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

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

More information

JAVA Programming Concepts

JAVA Programming Concepts JAVA Programming Concepts M. G. Abbas Malik Assistant Professor Faculty of Computing and Information Technology University of Jeddah, Jeddah, KSA mgmalik@uj.edu.sa Find the sum of integers from 1 to 10,

More information

C Programs: Simple Statements and Expressions

C Programs: Simple Statements and Expressions .. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar.. C Programs: Simple Statements and Expressions C Program Structure A C program that consists of only one function has the following

More information

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

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

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination October 7, 2013 Name: 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 the spaces

More information

Lecture 2:- Functions. Introduction

Lecture 2:- Functions. Introduction Lecture 2:- Functions Introduction A function groups a number of program statements into a unit and gives it a name. This unit can then be invoked from other parts of the program. The most important reason

More information

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>= Operators in java Operator in java is a symbol that is used to perform operations. For example: +, -, *, / etc. There are many types of operators in java which are given below: Unary Operator, Arithmetic

More information

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

More information

Object-Oriented Programming

Object-Oriented Programming Data structures Object-Oriented Programming Outline Primitive data types String Math class Array Container classes Readings: HFJ: Ch. 13, 6. GT: Ch. 13, 6. Đại học Công nghệ - ĐHQG HN Data structures 2

More information

Programming in C Quick Start! Biostatistics 615 Lecture 4

Programming in C Quick Start! Biostatistics 615 Lecture 4 Programming in C Quick Start! Biostatistics 615 Lecture 4 Last Lecture Analysis of Algorithms Empirical Analysis Mathematical Analysis Big-Oh notation Today Basics of programming in C Syntax of C programs

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2010) - All Sections Midterm Examination Thursday, March 11, 2010 Examiners: Milena Scaccia

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 05/07/2012 10:31 AM Input / Output Streams 2 of 21 05/07/2012 10:31 AM Java I/O streams

More information

Getting started with Java

Getting started with Java Getting started with Java by Vlad Costel Ungureanu for Learn Stuff Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine, particularly

More information

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of N heavenly bodies, subject

More information

1 class Lecture5 { 2 3 "Methods" / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / Zheng-Liang Lu Java Programming 176 / 199

1 class Lecture5 { 2 3 Methods / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / Zheng-Liang Lu Java Programming 176 / 199 1 class Lecture5 { 2 3 "Methods" 4 5 } 6 7 / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / Zheng-Liang Lu Java Programming 176 / 199 Methods 2 Methods can be used to define reusable code, and organize

More information

Selenium Class 9 - Java Operators

Selenium Class 9 - Java Operators Selenium Class 9 - Java Operators Operators are used to perform Arithmetic, Comparison, and Logical Operations, Operators are used to perform operations on variables and values. public class JavaOperators

More information

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

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved 1 Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a table. For example, the following table that describes

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 5/20/2013 9:37:22 AM Why Programming? Why programming? Need

More information

JME Language Reference Manual

JME Language Reference Manual JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

More information

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types COMP-202 Unit 6: Arrays Introduction (1) Suppose you want to write a program that asks the user to enter the numeric final grades of 350 COMP-202

More information

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

Prof. Navrati Saxena TA: Rochak Sachan

Prof. Navrati Saxena TA: Rochak Sachan JAVA Prof. Navrati Saxena TA: Rochak Sachan Operators Operator Arithmetic Relational Logical Bitwise 1. Arithmetic Operators are used in mathematical expressions. S.N. 0 Operator Result 1. + Addition 6.

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

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

More information

Lecture Static Methods and Variables. Static Methods

Lecture Static Methods and Variables. Static Methods Lecture 15.1 Static Methods and Variables Static Methods In Java it is possible to declare methods and variables to belong to a class rather than an object. This is done by declaring them to be static.

More information

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

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

More information

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name: CSC 1051-001 Algorithms and Data Structures I Midterm Examination February 25, 2016 Name: 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 the

More information

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination

Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2009) - All Sections Midterm Examination Tuesday, November 3, 2009 Examiners: Mathieu Petitpas

More information

Lecture Static Methods and Variables. Static Methods

Lecture Static Methods and Variables. Static Methods Lecture 15.1 Static Methods and Variables Static Methods In Java it is possible to declare methods and variables to belong to a class rather than an object. This is done by declaring them to be static.

More information

An Introduction to MATLAB

An Introduction to MATLAB An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High level language Programing language and development environment Built-in development tools Numerical manipulation Plotting of

More information

Strings and Arrays. Hendrik Speleers

Strings and Arrays. Hendrik Speleers Hendrik Speleers Overview Characters and strings String manipulation Formatting output Arrays One-dimensional Two-dimensional Container classes List: ArrayList and LinkedList Iterating over a list Characters

More information

Zheng-Liang Lu Java Programming 45 / 79

Zheng-Liang Lu Java Programming 45 / 79 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

More information

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters)

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters) Classes Classes/Objects/Interfaces (Savitch, Various Chapters) TOPICS Classes Public versus Private Static Data Static Methods Interfaces Classes are the basis of object-oriented (OO) programming. They

More information

Professor Peter Cheung EEE, Imperial College

Professor Peter Cheung EEE, Imperial College 1/1 1/2 Professor Peter Cheung EEE, Imperial College In this lecture, we take an overview of the course, and briefly review the programming language. The rough guide is not very complete. You should use

More information

CS111: PROGRAMMING LANGUAGE II

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

More information

A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts,

A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders,

More information

1.1 Your First Program

1.1 Your First Program A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders,

More information

Using Java Classes Fall 2018 Margaret Reid-Miller

Using Java Classes Fall 2018 Margaret Reid-Miller Using Java Classes 15-121 Fall 2018 Margaret Reid-Miller Today Strings I/O (using Scanner) Loops, Conditionals, Scope Math Class (random) Fall 2018 15-121 (Reid-Miller) 2 The Math Class The Math class

More information

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

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

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

CS115 Principles of Computer Science

CS115 Principles of Computer Science CS115 Principles of Computer Science Chapter 5 Methods Prof. Joe X. Zhou Department of Computer Science CS115 Methods.1 Re: Objectives in Loops Sequence and selection aside, we need repetition (loops)

More information

Preview from Notesale.co.uk Page 2 of 79

Preview from Notesale.co.uk Page 2 of 79 COMPUTER PROGRAMMING TUTORIAL by tutorialspoint.com Page 2 of 79 tutorialspoint.com i CHAPTER 3 Programming - Environment Though Environment Setup is not an element of any Programming Language, it is the

More information

TeenCoder : Java Programming (ISBN )

TeenCoder : Java Programming (ISBN ) TeenCoder : Java Programming (ISBN 978-0-9887070-2-3) and the AP * Computer Science A Exam Requirements (Alignment to Tennessee AP CS A course code 3635) Updated March, 2015 Contains the new 2014-2015+

More information

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java Chapter 5 Methods Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations

More information

Pace University. Fundamental Concepts of CS121 1

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

More information

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it

Last Class. Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it Last Class Introduction to arrays Array indices Initializer lists Making an array when you don't know how many values are in it public class February4{ public static void main(string[] args) { String[]

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 37 11/02/2012 05:24 PM Java - Control Flow 2 of 37 11/02/2012 05:24 PM controlling the

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Programming Language Basics

Programming Language Basics Programming Language Basics Lecture Outline & Notes Overview 1. History & Background 2. Basic Program structure a. How an operating system runs a program i. Machine code ii. OS- specific commands to setup

More information

Classes. Classes as Code Libraries. Classes as Data Structures

Classes. Classes as Code Libraries. Classes as Data Structures Classes Classes/Objects/Interfaces (Savitch, Various Chapters) TOPICS Classes Public versus Private Static Data Static Methods Interfaces Classes are the basis of object-oriented (OO) programming. They

More information

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2 CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,

More information

ECET 264 C Programming Language with Applications

ECET 264 C Programming Language with Applications ECET 264 C Programming Language with Applications Lecture 10 C Standard Library Functions Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 10

More information

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

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

More information

Programming Basics. Digital Urban Visualization. People as Flows. ia

Programming Basics.  Digital Urban Visualization. People as Flows. ia Programming Basics Digital Urban Visualization. People as Flows. 28.09.2015 ia zuend@arch.ethz.ch treyer@arch.ethz.ch Programming? Programming is the interaction between the programmer and the computer.

More information

1. Find the output of following java program. class MainClass { public static void main (String arg[])

1. Find the output of following java program. class MainClass { public static void main (String arg[]) 1. Find the output of following java program. public static void main(string arg[]) int arr[][]=4,3,2,1; int i,j; for(i=1;i>-1;i--) for(j=1;j>-1;j--) System.out.print(arr[i][j]); 1234 The above java program

More information

ENCE 688R Civil Information Systems. The Java Language. Mark Austin.

ENCE 688R Civil Information Systems. The Java Language. Mark Austin. p. 1/4 ENCE 688R Civil Information Systems The Java Language Mark Austin E-mail: austin@isr.umd.edu Department of Civil and Environmental Engineering, University of Maryland, College Park p. 2/4 Lecture

More information

JVM (java) compiler. A Java program is either a library of static methods (functions) or a data type definition

JVM (java) compiler. A Java program is either a library of static methods (functions) or a data type definition Programming Model Basic Structure of a Java Program The Java workflow editor (Code) P.java compiler (javac) P.class JVM (java) output A Java program is either a library of static methods (functions) or

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 2 Data types type: A category or set of data

More information

9 C Language Function Block

9 C Language Function Block 9 C Language Function Block In this chapter, we focus on C language function block s specifications, edition, instruction calling, application points etc. we also attach the common Function list. 9-1.Functions

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 1/29/11 6:37 AM! Why Programming? Why programming? Need to

More information

Computational Expression

Computational Expression Computational Expression Scanner, Increment/Decrement, Conversion Janyl Jumadinova 17 September, 2018 Janyl Jumadinova Computational Expression 17 September, 2018 1 / 11 Review: Scanner The Scanner class

More information

Chapter 8 Multi-Dimensional Arrays

Chapter 8 Multi-Dimensional Arrays Chapter 8 Multi-Dimensional Arrays 1 1-Dimentional and 2-Dimentional Arrays In the previous chapter we used 1-dimensional arrays to model linear collections of elements. myarray: 6 4 1 9 7 3 2 8 Now think

More information

1.00 Lecture 4. Promotion

1.00 Lecture 4. Promotion 1.00 Lecture 4 Data Types, Operators Reading for next time: Big Java: sections 6.1-6.4 Promotion increasing capacity Data Type Allowed Promotions double None float double long float,double int long,float,double

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

More information

McGill University School of Computer Science COMP-202A Introduction to Computing 1

McGill University School of Computer Science COMP-202A Introduction to Computing 1 McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 Copyright 2009 by Pearson Education Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 Copyright

More information

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Language Features. 1. The primitive types int, double, and boolean are part of the AP Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY CSC 1051 Algorithms and Data Structures I Midterm Examination October 9, 2014 Name: KEY 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 the

More information