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

 Alban Moody
 7 months ago
 Views:
Transcription
1 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, there is no need to import the class because it is automatically imported (by the java.lang package). The functions covered are the following: Method Description static double pow (double y, double x) Returns y raised to the x static double sqrt (double arg) Returns the square root of arg static int abs (int arg) Returns the absolute value of arg static double ceil (double arg) Returns the smallest whole number greater than or equal to arg static double floor (double arg) Returns the largest whole number less than or equal to arg static int round (float arg) Returns arg rounded up to the nearest int static long round (double arg) Returns arg rounded up to the nearest long static double random() Returns a random number between 0 and 1 The class name Math must be included each time the method is used. For instance: System.out.println(Math.pow(2,8)); The Math class Function Name Arguments Ms.P.Sullivan Page 1 of 6
2 In the previous example the Math class is being called and the pow method is called with the arguments of 2 and 8. This means that 2 to the power of 8 is worked out which will result in 256. If the result must be stored in a variable the statement can be changed to double result = Math.pow(2,8); Having to use the class name Math every time a function is required might be tedious, so it can be avoided by using the static import statement at the beginning (before the class declaration) import static.java.lang.math.*; and then the statement can be coded as double result = pow(2,8); So, you can choose whichever method you prefer, either use the import at the beginning or add the class name Math to each method you re using. Math.pow() import static java.lang.math.*; class Power { public static void main (String args[]){ int a = 5; int b = 6; System.out.println(pow(a,b)); This program will work out 5 to the power of 6 and it will display Math.sqrt() import static java.lang.math.*; class SquareRoot { public static void main (String args[]){ int a = 100; System.out.println(sqrt(a)); The above program will work out the square root of 100 and so it will result in 10. Ms.P.Sullivan Page 2 of 6
3 Maths.abs() The absolute value of a number is equal to the same number without the sign. It can be useful on calculations which require positive numbers only; for instance finding the square root of a negative number cannot be done, so first you work out the absolute value. import static java.lang.math.*; class SquareRoot { public static void main (String args[]){ double a = 5.4; System.out.println(abs(a)); This program will return the value of 5.4 since the negative symbol is dropped. Math.random() A random number is a computer generated number picked up from a set of numbers. random() returns a double number ranging from to This can be ideal if randomly generated numbers are required, such as rolling a dice or picking a number for the lotto. For instance, to generate a random number from 0 to 9 (inclusive) the following code can be used: int num = (int)(math.random() * 10); if the number required must be from 1 to 10, +1 must be added at the end. int num = (int)(math.random() * 10)+1; The Math.random() method returns a double number so the it must be type casted into an integer number by using (int). Randomly generated numbers start from 0, so if these must be started from 1, a +1 must be added at the end. For instance to generate a random number from 1 to 6, like a dice this code is required: int die = (int)(math.random()*6)+1; This will generate a random number from 1 to 6. Ms.P.Sullivan Page 3 of 6
4 Math.round() This method returns the closest value to the integer value of the number. If the fraction value is equal to or more than 0.5, it will add 1 to the original value. Math.round() will remove the fraction and just return the rounded whole number. It can accept a double value and return a long, or accept a float value and return an integer. For example double num1 = Math.round( ); will return 1235, whilst double num1 = Math.round( ); will return Math.ceil() This will return the smallest integer number which is not less than the supplied number. Method Result Math.ceil(11); 11 Math.ceil(11.3); 12 Math.ceil(13.4); 13 Math.floor() This will return the largest integer number which is not greater than the supplied number. Method Result Math.floor(11); 11 Math.floor(11.3); 11 Math.floor(13.4); 14 Ms.P.Sullivan Page 4 of 6
5 Formatting values printf() To format text a specified number of decimal places printf() can be used instead of println(). When using printf(), the placeholders must be specified inside the message (inside the quotes), followed by the variable. For instance: int num = 5; System.out.printf( %d\n,num); In this case what happens is 5 will be displayed on a line, then the cursor will move to the next line. This happens because the %d is replaced with the value of num and then the escape character \n is applied. There are different placeholders for different data types: Placeholder Used for %d int, byte, short, long %f float %s String %c char When using %f the number of decimal places can be specified as well. For instance: System.out.printf( Formatted to 2 decimal places :%.2f\n,ans); A field can also be used to hold a number. In this example a field of size 10 is created to display the number: System.out.printf( Formatted to 2 decimal places :%10.2f\n,ans); Finally, if the empty spaces are to filled in with zeros it can be coded as: System.out.printf( Formatted to 2 decimal places :%010.2f\n,ans); Ms.P.Sullivan Page 5 of 6
6 Activities 1. Develop an application naming it PowerOf to ask the user to input a number between 2 and 10 and then output: a. The number inputted to the power of 3 b. The number inputted to the power of 5 2. Write an application named FindSquareRt to output the square root of +144 and also the square root of 25. (Note: you have to use abs() in the case of 25. Why?) 3. Create an application to simulate the Super Five lottery. That is you need to generate one number between 1 and Lotto draws can generate a number between 1 and 90. Create an application that generates one number for the lotto draw. 5. Create a class naming it MyRound to round and output the following values to integers: a b c *** Ms.P.Sullivan Page 6 of 6
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 informationA Balanced Introduction to Computer Science, 3/E
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN 9780132166751 Chapter 7 Functions and Randomness 1 Predefined Functions recall: in
More informationA Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN
A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN 9780132166751 Chapter 7 Functions and Randomness 1 Predefined Functions recall: in
More informationCS110: 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 informationTo define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easytoread, easytodebug,
1 To define methods, invoke methods, and pass arguments to a method ( 5.25.5). To develop reusable code that is modular, easytoread, easytodebug, and easytomaintain. ( 5.6). To use method overloading
More informationThe 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 informationMethods: A Deeper Look
1 2 7 Methods: A Deeper Look OBJECTIVES In this chapter you will learn: How static methods and variables are associated with an entire class rather than specific instances of the class. How to use randomnumber
More informationAP CS Unit 3: Control Structures Notes
AP CS Unit 3: Control Structures Notes The if and ifelse Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts
More informationCT 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
More informationChapter 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 informationstatic 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 informationPace 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 informationFunctions, Randomness and Libraries
Functions, Randomness and Libraries 1 Predefined Functions recall: in mathematics, a function is a mapping from inputs to a single output e.g., the absolute value function: 5 5, 17.3 17.3 in JavaScript,
More informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 7: Return values, Math, and casting reading: 3.2, 2.12.2 (Slides adapted from Stuart Reges, Hélène Martin, and Marty Stepp) Copyright 2011 by Pearson Education
More informationFormatting 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
More informationChapter 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 informationChapter 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 informationVariables, Types, Operations on Numbers
Variables, Types, Operations on Numbers CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Updated 9/6/16 1 Summary Variable declaration, initialization,
More informationChapter 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 informationKey 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
More informationMethods (Deitel chapter 6)
1 Plan 2 Methods (Deitel chapter ) Introduction Program Modules in Java MathClass Methods Method Declarations Argument Promotion Java API Packages RandomNumber Generation Scope of Declarations Methods
More informationCOP3502 Programming Fundamentals for CIS Majors 1. Instructor: Parisa Rashidi
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi Chapter 4 Loops for while dowhile Last Week Chapter 5 Methods Input arguments Output Overloading Code reusability Scope of
More informationMathematical 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 informationBuilding Java Programs
Building Java Programs Chapter 3 Return values, Math, and double reading: 3.2, 2.12.2 Copyright 2011 by Pearson Education 2 Java's Math class Method name Math.abs(value) Math.ceil(value) Math.floor(value)
More informationWhat 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
More informationC++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 6: UserDefined Functions I
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 6: UserDefined Functions I In this chapter, you will: Objectives Learn about standard (predefined) functions and discover
More informationImportant 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
More informationCOSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand
COSC 236 Section 101 Computer Science 1  Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.classnotes.us From this site you can click on the COSC236
More informationFunction I/O. Function Input and Output. Input through actual parameters. Output through return value. Input/Output through side effects
Function Input and Output Input through actual parameters Output through return value Only one value can be returned Input/Output through side effects printf scanf 2 tj Function Input and Output int main(void){
More information1 class Lecture5 { 2 3 "Methods" / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / ZhengLiang 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 / ZhengLiang Lu Java Programming 176 / 199 Methods 2 Methods can be used to define reusable code, and organize
More informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 32: Return values, Math, and double reading: 3.2, 2.12.2 Java's Math class Method name Math.abs(value) Math.ceil(value) Math.floor(value) Description absolute
More informationAdvanced Object Concepts
Understanding Blocks Blocks  Appears within any class or method, the code between a pair of curly braces Outside block The first block, begins immediately after the method declaration and ends at the
More informationCoding in JavaScript functions
Coding in JavaScript functions A function contains code that will be executed by an event or by a call to the function. You may call a function from anywhere within a page (or even from other pages if
More informationLESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long
LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be
More informationJAVASCRIPT BASICS. JavaScript Math Functions. The Math functions helps you to perform mathematical tasks
JavaScript Math Functions Functions The Math functions helps you to perform mathematical tasks in a very way and lot of inbuilt mathematical functions which makes the programmers life easier. Typical example
More informationModule 4: Characters, Strings, and Mathematical Functions
Module 4: Characters, Strings, and Mathematical Functions Objectives To solve mathematics problems by using the methods in the Math class ( 4.2). To represent characters using the char type ( 4.3). To
More informationFunctions. Systems Programming Concepts
Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value
More informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationTopic 12 more if/else, cumulative algorithms, printf
Topic 12 more if/else, cumulative algorithms, printf "We flew down weekly to meet with IBM, but they thought the way to measure software was the amount of code we wrote, when really the better the software,
More informationint: integers, no fractional part double: floatingpoint numbers (double precision) 1, 4, 0 0.5, , 4.3E24, 1E14
int: integers, no fractional part 1, 4, 0 double: floatingpoint numbers (double precision) 0.5, 3.11111, 4.3E24, 1E14 A numeric computation overflows if the result falls outside the range for the number
More informationDefine a method vs. calling a method. Chapter Goals. Contents 1/21/13
CHAPTER 2 Define a method vs. calling a method Line 3 defines a method called main Line 5 calls a method called println, which is defined in the Java library You will learn later how to define your own
More informationBuilding Java Programs
Building Java Programs Chapter 3 Lecture 32: Return values, Math, and double reading: 3.2, 2.12.2 Method name Math.abs(value) Math.ceil(value) Math.floor(value) Java's Math class Description absolute
More informationActivity 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
More informationChapter 3  Functions
Chapter 3  Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number
More informationChapter 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 informationBuiltin data types. logical AND logical OR logical NOT &&! public static void main(string [] args)
Builtin data types logical AND logical OR logical NOT &&! public static void main(string [] args) Fundamentals of Computer Science Keith Vertanen Copyright 2013 Variables Variables and data types Stores
More informationCS 302: Introduction to Programming
CS 302: Introduction to Programming Lectures 23 CS302 Summer 2012 1 Review What is a computer? What is a computer program? Why do we have highlevel programming languages? How does a highlevel program
More informationAll classes in a package can be imported by using only one import statement. If the postcondition of a method is not met, blame its implementer
Java By Abstraction ANSWERS O ESA GROUP  A For each question, give +0.5 if correct, 0.5 if wrong, and 0 if blank. If the overall total is negative, record it (on the test's cover sheet)
More informationBuiltin data types. public static void main(string [] args) logical AND logical OR logical NOT &&! Fundamentals of Computer Science
Builtin data types logical AND logical OR logical NOT &&! public static void main(string [] args) Fundamentals of Computer Science Variables Overview Allows us to store and compute on data For now we'll
More informationECET 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 informationWelcome 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
More informationC++, How to Program. Spring 2016 CISC1600 Yanjun Li 1
Chapter 6 Function C++, How to Program Deitel & Deitel Spring 2016 CISC1600 Yanjun Li 1 Function A function is a collection of statements that performs a specific task  a single, welldefined task. Divide
More informationICSE Class 10 Computer Applications ( Java ) 2014 Solved Question Paper
1 of 10 0511015 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
More informationBasic types and definitions. Chapter 3 of Thompson
Basic types and definitions Chapter 3 of Thompson Booleans [named after logician George Boole] Boolean values True and False are the result of tests are two numbers equal is one smaller than the other
More informationUNIT  I. Introduction to C Programming. BY A. Vijay Bharath
UNIT  I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a generalpurpose programming language. It has been
More informationHow to Think... Chapter 3
1 Professor: Sana Odeh odeh@courant.nyu.edu Functions Math Functions (generating random functions) Reading: How to Think... Chapter 3 2 Functions Two types of Functions: Builtin functions: (efficient
More informationME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double
ME 172 Lecture 2 variables scanf() printf() 07/03/2011 ME 172 1 Data Types and Modifier Basic data types are char int float double Modifiers signed unsigned short Long 07/03/2011 ME 172 2 1 Data Types
More information4. C++ functions. 1. Library Function 2. Userdefined Function
4. C++ functions In programming, function refers to a segment that group s code to perform a specific task. Depending on whether a function is predefined or created by programmer; there are two types of
More informationFirst Programs. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington
First Programs CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Output System.out.println( ) prints out something. System.out.println is the first
More informationCS211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, Name:
CS211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, 2017 True/False Questions... Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a)
More informationLecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University
Lecture 2 COMP1406/1006 (the Java course) Fall 2013 M. Jason Hinek Carleton University today s agenda a quick look back (last Thursday) assignment 0 is posted and is due this Friday at 2pm Java compiling
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All for repetition statement do while repetition statement switch multipleselection statement break statement continue statement Logical
More informationScheme Quick Reference
Scheme Quick Reference COSC 18 Fall 2003 This document is a quick reference guide to common features of the Scheme language. It is not intended to be a complete language reference, but it gives terse summaries
More informationMATHEMATICAL / NUMERICAL FUNCTIONS
MATHEMATICAL / NUMERICAL FUNCTIONS Function Definition Syntax Example ABS (Absolute value) ASC It returns the absolute value of a number, turning a negative to a positive (e.g.  4 to 4) It returns the
More informationCS/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
More informationJava Methods. Lecture 8 COP 3252 Summer May 23, 2017
Java Methods Lecture 8 COP 3252 Summer 2017 May 23, 2017 Java Methods In Java, the word method refers to the same kind of thing that the word function is used for in other languages. Specifically, a method
More informationFunctions. 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 selfcontained program segment that
More informationCISC124. This week we continued to look at some aspects of Java and how they relate to building reliable software.
CISC124 20180129 20180130 20180201 This week we continued to look at some aspects of Java and how they relate to building reliable software. MultiDimensional Arrays Like most languages, Java permits
More informationSection 2.2 Your First Program in Java: Printing a Line of Text
Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: Endofline comments that should be ignored by the compiler are denoted using a. Two
More informationChapter 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
More informationFundamentals of Programming Session 8
Fundamentals of Programming Session 8 Instructor: Reza EntezariMaleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationExercise: Using Numbers
Exercise: Using Numbers Problem: You are a spy going into an evil party to find the supersecret code phrase (made up of letters and spaces), which you will immediately send via text message to your team
More informationProgramming Exercise 7: Static Methods
Programming Exercise 7: Static Methods Due date for section 001: Monday, February 29 by 10 am Due date for section 002: Wednesday, March 2 by 10 am Purpose: Introduction to writing methods and code reuse.
More informationToday. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed
CS 150 Introduction to Computer Science I Data Types Today Last we covered o main function o cout object o How data that is used by a program can be declared and stored Today we will o Investigate the
More informationIntroduction to. Copyright HKTA Tang Hin Memorial Secondary School 2016
Introduction to 2 VISUAL BASIC 2016 edition Copyright HKTA Tang Hin Memorial Secondary School 2016 Table of Contents. Chapter....... 1.... More..... on.. Operators........................................
More informationNumerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University
Numerical Data CS 180 Sunil Prabhakar Department of Computer Science Purdue University Problem Write a program to compute the area and perimeter of a circle given its radius. Requires that we perform operations
More informationUNITI Input/ Output functions and other library functions
Input and Output functions UNITI Input/ Output functions and other library functions All the input/output operations are carried out through function calls. There exists several functions that become
More informationMultiple Choice Questions ( 1 mark)
Multiple Choice Questions ( 1 mark) Unit1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s
More informationFunctions. 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 selfcontained program segment that carries
More informationCS115 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 informationVariable Scope. The variable scope is the range of the program where the variable can be referenced.
Variable Scope The variable scope is the range of the program where the variable can be referenced. Variables can be declared in class level, method level, and loop level. In general, a pair of curly brackets
More informationCS 335 Lecture 02 Java Programming
1 CS 335 Lecture 02 Java Programming Programming in Java Define data Calculate using data Output result Java is objectoriented: Java program must: Merge data and functions into object Invoke functions
More informationFunctions in C++ ProblemSolving Procedure With Modular Design C ++ Function Definition: a single
Functions in C++ ProblemSolving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module
More informationCHAPTER 4 MATHEMATICAL FUNCTIONS, CHARACTERS, STRINGS
CHAPTER 4 MATHEMATICAL FUNCTIONS, CHARACTERS, STRINGS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH INTRODUCTION TO JAVA PROGRAMMING, LIANG (PEARSON 2014) MATHEMATICAL FUNCTIONS Java
More informationFunctions. Lecture 6 COP 3014 Spring February 11, 2018
Functions Lecture 6 COP 3014 Spring 2018 February 11, 2018 Functions A function is a reusable portion of a program, sometimes called a procedure or subroutine. Like a miniprogram (or subprogram) in its
More informationProgramming in Java
320341 Programming in Java Fall Semester 2015 Lecture 2: Fundamental Structures Instructor: Jürgen Schönwälder Slides: Bendick Mahleko Outline  Program structure  Data types  Variables  Constants 
More informationName Course Days/Start Time
Name Course Days/Start Time MiniProject : The Library of Functions In your previous math class, you learned to graph equations containing two variables by finding and plotting points. In this class, we
More informationTable : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (
Floating Point Numbers in Java by Michael L. Overton Virtually all modern computers follow the IEEE 2 floating point standard in their representation of floating point numbers. The Java programming language
More informationData types, variables, constants
Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision
More informationProgramming and Data Structure Tutorial sheet: 1 Topics: Data Handling, Operators and Expressions, Input and Output Operations.
Programming and Data Structure Tutorial sheet: 1 Topics: Data Handling, Operators and Expressions, Input and Output Operations. Q1. (a) Which one of the following is a valid name of a C variable: 2ab_c,
More informationMODULE 02: BASIC COMPUTATION IN JAVA
MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment
More informationOn a 64bit CPU. Size/Range vary by CPU model and Word size.
On a 64bit CPU. Size/Range vary by CPU model and Word size. unsigned short x; //range 0 to 65553 signed short x; //range ± 32767 short x; //assumed signed There are (usually) no unsigned floats or doubles.
More informationLecture 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
More informationNumber Systems, Scalar Types, and Input and Output
Number Systems, Scalar Types, and Input and Output Outline: Binary, Octal, Hexadecimal, and Decimal Numbers Character Set Comments Declaration Data Types and Constants Integral Data Types FloatingPoint
More informationFall Semester (081) Dr. ElSayed ElAlfy Computer Science Department King Fahd University of Petroleum and Minerals
INTERNET PROTOCOLS AND CLIENTSERVER PROGRAMMING Client SWE344 request Internet response Fall Semester 20082009 (081) Server Module 2.1: C# Programming Essentials (Part 1) Dr. ElSayed ElAlfy Computer
More information1.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 informationCOSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan
COSC 123 Computer Creativity Introduction to Java Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Introduce Java, a generalpurpose programming language,
More informationCS 312 Exam 1 Fall KG Kris Megan Roman Sonika
CS 312 Exam 1 Fall 2015 Name: SOLUTION SOLUTION SOLUTION UTEID: SOLUTION SOLUTION SOLUTION _ Circle your TA's Name: Aila CK Jialin Katherine B KG Kris Megan Roman Sonika Problem Number Topic Points Possible
More informationFloating Point Puzzles The course that gives CMU its Zip! Floating Point Jan 22, IEEE Floating Point. Fractional Binary Numbers.
class04.ppt 15213 The course that gives CMU its Zip! Topics Floating Point Jan 22, 2004 IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Floating Point Puzzles For
More informationDeclaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.
Declaration Fundamental Data Types All variables must be declared before being used. Tells compiler to set aside an appropriate amount of space in memory to hold a value. Enables the compiler to perform
More information