{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

NumericDataNew

# NumericDataNew - Numerical Data CS 180 Sunil Prabhakar...

This preview shows pages 1–9. Sign up to view the full content.

Numerical Data CS 180 Sunil Prabhakar Department of Computer Science Purdue University Sunday, January 22, 2012

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
© Sunil Prabhakar, Purdue University Problem Write a program to compute the area and perimeter of a circle given its radius. Requires that we perform operations on numbers Strings or other standard classes are not appropriate for this purpose. Instead, we will use a special type of data 2 Sunday, January 22, 2012
© Sunil Prabhakar, Purdue University Primitive Data Types As all matter is fundamentally composed of atoms, all objects are fundamentally composed of primitive data types. Primitive types are the building blocks of all data used in Java. Primitive data types are neither classes nor objects. ¡ਟ They are so simple, that we don't need the overhead of objects Each type can be processed using only specific operators 3 Sunday, January 22, 2012

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
© Sunil Prabhakar, Purdue University Primitive Data Types Numeric ¡ਟ e.g., 2, 3, 3.1416, ¡ਟ for storing and operating on integer and real valued data Character ¡ਟ e.g., 'a', ' ', ' ', ' ', ' ', ' ࠴͍ ', ' ', ' ', ' ', ' ש ' ,' ۻ ' ¡ਟ for capturing characters for (almost) all world languages Boolean ¡ਟ only two allowed valued: true , false ¡ਟ logic data type This week we will study Numeric data. 4 Sunday, January 22, 2012
© Sunil Prabhakar, Purdue University import java.util.Scanner; public class CircleCalculator { public static void main (String[] args){ double radius, area, circumference; Scanner scanner = new Scanner(System.in); System.out.println( "Enter radius" ); radius = scanner.nextDouble(); circumference = 2.0 * 3.14 * radius; area = 3.14 * radius * radius; System.out.println( "Given Radius: " + radius + "\n" + "Area: " + area + "\n" + "Circumference: " + circumference); } } Area and Perimeter 5 Not a class Sunday, January 22, 2012

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
© Sunil Prabhakar, Purdue University Important Points Note the use of = ¡ਟ do not confuse this with the = symbol from mathematics ¡ਟ circumference = 2 * 3.14 * radius; computes the product of 2, 3.14, and the numeric value stored in radius , and copies this value into circumference ¡ਟ This is an assignment statement . Causes the value stored in circumference to change. 6 Sunday, January 22, 2012
© Sunil Prabhakar, Purdue University 7 Variables Data items such as area are called variables . ¡ਟ since we can change their values during program execution. A variable has three properties: ¡ਟ A memory location to store the value, ¡ਟ The type of data stored in the memory location, and ¡ਟ The name used to refer to the memory location. When the declaration double area; is made, ¡ਟ memory space is allocated to store a real number value ¡ਟ area is a reference for this space. Sunday, January 22, 2012

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
© Sunil Prabhakar, Purdue University 8 Assignment Statements We set the value of a variable using an assignment statement .
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 48

NumericDataNew - Numerical Data CS 180 Sunil Prabhakar...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online