Department of Computer Engineering Working With Data 2140101 Computer Programming for International Engineers.

Slides:



Advertisements
Similar presentations
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Advertisements

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Numerical Data Recitation – 01/30/2009
CS180 Recitation 3. Lecture: Overflow byte b; b = 127; b += 1; System.out.println("b is" + b); b is -128 byte b; b = 128; //will not compile! b went out.
Data types and variables
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
String Escape Sequences
Basic Elements of C++ Chapter 2.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Java Chapter 2 Creating Classes. Class Defines structure of an object or set of objects; Includes variables (data) and methods (actions) which determine.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
***** SWTJC STEM ***** Chapter 2-2 cg Identifiers - Naming Identifier, the name of a Java programming component. Identifier naming rules... Must.
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CSC Programming I Lecture 5 August 30, 2002.
Chapter 2: Using Data.
Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
November 1, 2015ICS102: Expressions & Assignment 1 Expressions and Assignment.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 CS 007: Introduction to Computer Programming Ihsan Ayyub Qazi.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
COMP Primitive and Class Types Yi Hong May 14, 2015.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
CS 106 Introduction to Computer Science I 09 / 10 / 2007 Instructor: Michael Eckmann.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Java Variables and Types
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Introduction to C++ Programming
Chapter 2: Basic Elements of Java
Chapter 2 Variables.
Chapter 2: Java Fundamentals
Building Java Programs Chapter 2
Expressions and Assignment
Building Java Programs
Primitive Types and Expressions
Building Java Programs Chapter 2
Building Java Programs
Presentation transcript:

Department of Computer Engineering Working With Data Computer Programming for International Engineers

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Objectives Students should: Be familiar with the eight primitive data types and non-primitive data types. Understand memory allocations and value assignments of variables. Be able to use operators and some methods to do some computations.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Data Types in Java There are 2 main types of data in Java. –Primitive data types. –Classes. Primitive data types. –They cannot be added or changed. –There are 8. 4 types for integer values. 2 types for floating-point values. 1 type for characters. 1 type for logical values (true/false). Classes (we’ll look at this later).

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Data Types Value typePrimitive data types Integer (E.g.: 5, -1, 0, etc.) byte, short, int, long Floating-point (E.g.: 1.0, 9.75, -3.06, etc.) float, double Character (E.g.: ‘a’, ‘ ก ’, ‘4’, etc.) char Logical (true/false) boolean

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Data Type for Integers Why does Java have multiple integer (as well as, floating-point) types? –Allow programmer to access all the types support natively by various computer hardware. Sizes of the space they occupied in memory are different. –Let the program works efficiently.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Data Type for Integers(2) Recall that a space of 1 byte (8 bits) can store 28 different things. A byte occupies 1 byte of memory. –It can represent one of 2 8 (256) integers in the range -128, -127, …, 0, 1, …, 126, 127. A short occupies 2 bytes of memory. –It can represent one of 2 16 (65,536) integers in the range -32,678, …, 0, 1, …, 32,767.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Data Type for Integers(3) An int occupies 4 bytes of memory. –It can represent one of 2 32 (4,294,967,296) integers in the range -2,147,483,648, …, 0, 1, …, 2,147,483,647. A long occupies 8 bytes of memory. –It can represent one of 2 64 integers in the range -2 63, …, 0, 1, …, The default primitive type for integer value is int. See example Program, TestingIntegers

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Types for Floating-Point Values The default primitive type for integer value is double. A float occupies 4 bytes of memory. –Its range is from -3.4  to 3.4  10 38, with typical precision of 6-9 decimal points. A double occupies 8 bytes of memory. –Its range is from -1.8  to 1.8  , with typical precision of decimal points.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Types for Floating-Point Values(2) There are two ways to write floating-point values. –Decimal Notation, such as , 0.001, 1.0, 8.357, 1., and.9 –Scientific Notation, such as E 2, 10 E -4, 1 E 0, E 1, 1000 E -3, and 9.0 E -1 represent  10 2, 10  10 -4, 1  10 0,  10 1, 1000  10 -3, and 9.0  respectively. The character E can also be replaced with e. See example program, FloatAndDoubleTest

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Type for Characters The primitive data type for characters is char. A character is represented with single quotes. –For example: ‘Q’. Characters include –alphabets in different languages (‘a’, ‘b’, ‘ ก ’) –numbers in different languages (‘1’, ‘2’, ‘ ๑ ’) –symbols (‘%’, ‘#’, ‘{‘) –escape sequences (‘\t’, ‘\n’, ‘\”’)

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Type for Characters(2) The underlying representation of a char is an integer in the Unicode character set coding. Characters are encoded in 2 bytes Character Unicode encoding ‘A’65 ‘B’66 ‘a’97 ‘b’98 ‘1’49 ‘#’35

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Unicode Encoding of Characters Unicode character set encoding guarantees that ‘0’ < ’1’ < ’2’ < … < ’9’, ‘a’ < ’b’ < ‘c’ < … < ‘z’, and ‘A’ < ‘B’ < ‘C’ < … < ‘Z’. ‘0’+1 is ‘1’, ‘1’+2 is ‘3’, …, ‘8’+1 is ‘9’ ‘a’+1 is ‘b’, ‘b’+1 is ‘c’, …, ‘y’+1 is ‘z’ ‘A’+1 is ‘B’, ‘B’+1 is ‘C’, …, ‘Y’+1 is ‘Z’

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Primitive Type for Logical Values boolean is used for logical values. The size of this type is 1 bit. –True and false. 0 does not mean ‘false’ and 1 does not mean ‘true’.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY String Not a primitive data type. It is a class. –representing a sequence of one or more characters. Double quotes are used to designate the String type. –For example, “ISE” is a data of String type. –Be aware that “100” is not the same as the integer 100, and “Q” is not the same as the character ‘Q’.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Declaring Variables Variable types are specified when the variables are declared, using the name of the desired data types followed by the name of the variables. Do not forget semicolons at the end. char z; byte x; int j,k,l; boolean isit;

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Assigning Data to Variables assignment operator (=) Variables have types. A variable can only store a value that has the same data type as itself, unless the conversion can be done automatically (more on this later). z = ‘m’; isit = false; j=x; x=j; // wrong int byte See example program TestAssigningData

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY What are stored in actual memory? Variable with primitive data type –memory space of the size corresponding to its type is allocated. –The allocated space is used for storing the value of that type. Variable with Class type –The memory space allocated for such a variable is called a reference. –When assigned with a value, the reference points, or refers, to the memory location that actually stores that value.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY What are stored in actual memory?(2) char c = ‘A’ 65 String c = “A” cc c “A”

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Example of Assignments int x;1 double d;2 char c;3 boolean b;4 String s;5 x = 256;6 d = 1.5;7 c = ‘Q’;8 b = true;9 s = “Computer”10 xdcbs ‘Q’true “Computer” No space reserved in memory yet ‘Q’ true ‘Q’

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY String Assignments String s1, s2; s1 = “John”; s2 = “Mary”; s1 = s2; s1s2 “John”“Mary” “John” “Mary”“John”

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Another Assignment Example int x,y = 8; //two variables declared //in one statement double z = 0.6, w; double k=3.0; w = k; x = y; the integer value 8 is only assigned to y the double value stored in k is assigned to the variable w the int value stored in y is assigned to the variable x

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Bad Examples int i = 9// no semicolon at the end int j = 1.0;// mismatch data type boolean done = “false”;// mismatch data type char input character = ‘x’;// syntax error or illegal identifier Int k = 1;// Undefined data type double k; m = 5e-13;// undefined variable m char class = ‘A’;// use a reserve word as an identifier String s = ‘W’;// mismatch data type int i; int k = 2; int i = 6;// declaration of redundant variable i

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Final Variables cannot or will not be changed as long as the program has not terminated. The keyword final is used when a variable is declared –so that the value of that variable cannot be changed once it is initialized, or assigned for the first time. Programmers usually use all-uppercase letters for the identifiers of final variables, and use underscore (_) to separate words. –Examples: YOUNG_S_MODULUS, SPEED_OF_LIGHT

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Final Variables: Examples The following code segment will produce an error final double G = 6.67e10-11; final double SPEED_OF_SOUND; SPEED_OF_SOUND = 349.5; final int C; int k = 6; C = 80; C = k + 300; Error, due to the assignment in the last line.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Un-initialized Variables When a variable is declared, a space in the memory is reserved for the size of the type of that variable. However, as long as it is not assigned with a value, the variable does not contain any meaningful value. It is said that the variable has not been intitialized. If the value of an un-initialized variable is used, an error occurs.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Un-initialized Variables(2) int x, y = 2; System.out.println(x+y); Causes an error

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Operators Values can be manipulated –using built-in arithmetic operators +, -, *, /, %, -(means “negation”) –logic operators &&, ||, !(means “not”) –methods abs(), sqrt(), exp(), floor(), log(), getTime()) We will skip methods for now.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Logic Operators Logic operatorUsage && a&&b yields true if and only if both a and b are true. || a||b yields false if and only if both a and b are false. ! !a yields the opposite logical value of a.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Operator Categories Operators that require two operands are called binary operators. Operators that require only one operand are called unary operators. Parentheses, (), are called grouping operators. They indicate the portions of the calculation that have to be done first.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Operator Categories(2) equality operators, = = and !=, – a==b yields true if and only if a and b have the same logical value. – a!=b yields true if and only if a and b have different logical value. –Comparison can also be done using, =.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Assignment and operators: Examples int i = 2, j, k; j = 3; k = i + j; i = i + k; ijk boolean p = true; boolean q = false, r = true, s; s = p && q; s = s || r; p = (s == q); truefalse true falsetruefalsetruefalsetrue falsetrue pqsr

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY String and the addition operator (+) Concatenate two Strings together String s1 = “Computer”, s2 = “ized”, s3; s3 = s1 + s2; s3 will contain “Computerized”.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY String and the addition operator (+) (2) If a String is added with values of different data types, the compiler will try to convert the values that are not String to String automatically. Good news is that the automatic conversion usually returns the String that makes very much sense!

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY String Concatenation Example public class StringConcat 1 { 2 public static void main(String[] args) 3 { 4 double distance, speed; 5 distance = 2500; // meters 6 speed = 80; // km per hour 7 System.out.print("It would take a car running at "+speed+" km/h ");8 System.out.print((distance/1000/speed)*60*60+" sec. to travel "); 9 System.out.println(distance/1000+" km."); 10 } 11 }

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Some useful methods Math.abs( ); –returns the absolute value of the input value. Math.round( ); –returns the integer nearest to the input value. Math.ceil( ); –returns the smallest integer that is bigger than or equal to the input value. Math.floor( ); –returns the biggest integer that is smaller than or equal to the input value. Math.exp( ); –returns the exponential of the input value. Math.max(, ); –returns the bigger between the two input values.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Some useful methods(2) Math.min(, ); –returns the smaller between the two input values. Math.pow(, ); –returns the value of the first value raised to the power of the second value. Math.sqrt( ); –returns the square root of the input value. Math.sin( ); –returns the trigonometric sine value of the input value. Math.cos( ); –returns the trigonometric cosine value of the input value. Math.tan( ); –returns the trigonometric tangent value of the input value.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Useful Methods Example public class MathTest { public static void main(String[] args) { double a = 2.8, b = 3.1, c = 6.0; System.out.println("a+b \t\t= " + (a+b)); System.out.println("|a| \t\t= " + Math.abs(a)); System.out.println("round(a) \t= " + Math.round(a)); System.out.println("ceil(a) \t= " + Math.ceil(a)); System.out.println("floor(a) \t= " + Math.floor(a)); System.out.println("exp(a) \t\t= " + Math.exp(a)); System.out.println("max of a and b \t= " + Math.max(a,b)); System.out.println("min of a and b \t= " + Math.min(a,b)); System.out.println("2^c \t\t= "+Math.pow(2,c)); } } }}}}

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Precedence and Associativity int myNumber = * 6; 30 if the addition operator is executed first, but 15 if the multiplication operator is executed first. In fact, Java compiler has no problem with such ambiguity. Order of the operators can be determined using Precedence and association rules.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Precedence and Associativity(2) Operators with higher precedence levels are executed before ones with lower precedence levels. Associativity is also assigned to operators with the same precedence level. It indicates whether operators to the left or to the right are to be executed first. In any case, expressions in parentheses () are executed first. In the case of nested parentheses, the expression in the innermost pair is executed first.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Precedence and Associativity(3) OperatorPrecedenceAssociativity Grouping operator ( () ) 17 None Unary operator (+, -, !) 13 Right Multiplicative operator (*, /, %) 12 Left Additive operator (+, -) 11 Left Relational ordering (, =) 10 Left Relational equality (==, !=) 9 Left Logical and (&&) 4 Left Logical or (||) 3 Left Assignment (=) 1 Right

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Precedence and Associativity Examples *3.0–1.0/0.5 >= 5.0%2.0&& = =0 is equivalent to: ((-9.0)+(5.0*3.0)–(1.0/0.5) >= (5.0%2.0))&&((( )-9.0)= =0) ((-9.0) >= 1.0 )&&(( )= =0) ( 4.0 >= 1.0 )&&( 0 = =0) ( true )&&( true ) true.

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Precedence and Associativity Examples(2) The distance, d, between two points in the three-dimensional space ( x1,y1,z1 ) and ( x2,y2,z2 ) can be computed from: Next page shows the program

Department of Computer Engineering Computer Programming for International Engineers I NTERNATIONAL S CHOOL OF E NGINEERING C HULALONGKORN U NIVERSITY Precedence and Associativity Examples(3) public class Distance3d { public static void main(String[] args) { double x1,y1,z1,x2,y2,z2, d; double xDiff, yDiff, zDiff; x1 = 2.0; y1 = 1.0; z1 = 3.0; x2 = 0.0; y2 = 0.0; z2 = 6.0; xDiff = x1-x2; yDiff = y1-y2; zDiff = z1-z2; d = Math.sqrt(xDiff*xDiff+yDiff*yDiff+zDiff*zDiff); System.out.print("The distance between ("+x1+","+y1+","+z1+") and"); System.out.println(" ("+x2+","+y2+","+z2+") is "+d+"."); } Run it and see the result. That’s it for today.