NumericDataNew - Numerical Data CS 180 Sunil Prabhakar...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Numerical Data CS 180 Sunil Prabhakar Department of Computer Science Purdue University Sunday, January 22, 2012 Sunil Prabhakar, Purdue University Problem Write a program to compute the area and perimeter of a circle given its radius. n Requires that we perform operations on numbers n Strings or other standard classes are not appropriate for this purpose. n Instead, we will use a special type of data 2 Sunil Prabhakar, Purdue University Problem Write a program to compute the area and perimeter of a circle given its radius. n Requires that we perform operations on numbers n Strings or other standard classes are not appropriate for this purpose. n Instead, we will use a special type of data 2 Sunday, January 22, 2012 Sunil Prabhakar, Purdue University Primitive Data Types n As all matter is fundamentally composed of atoms, all objects are fundamentally composed of primitive data types. n Primitive types are the building blocks of all data used in Java. n Primitive data types are neither classes nor objects. They are so simple, that we don't need the overhead of objects n Each type can be processed using only specific operators 3 Sunday, January 22, 2012 Sunil Prabhakar, Purdue University Primitive Data Types n Numeric e.g., 2, 3, 3.1416, for storing and operating on integer and real valued data n Character e.g., 'a', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' ,' ' for capturing characters for (almost) all world languages n Boolean only two allowed valued: true , false logic data type n 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 Sunil Prabhakar, Purdue University Important Points n Note the use of = do not confuse this with the = symbol from mathematics circumference = 2 * 3.14 * radius; n computes the product of 2, 3.14, and the numeric value stored in radius , n 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 n Data items such as area are called variables . since we can change their values during program execution....
View Full Document

This note was uploaded on 02/19/2012 for the course CS 180 taught by Professor Staff during the Spring '08 term at Purdue University-West Lafayette.

Page1 / 48

NumericDataNew - Numerical Data CS 180 Sunil Prabhakar...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online