Class Notes (1,019,826)
CA (585,679)
Dancy (10)
Lecture 4

PROG 10082 Lecture Notes - Lecture 4: Object-Oriented Programming, Mathematical Constant, Law And JusticePremium

4 pages81 viewsWinter 2016

Computer Engineering Technology
Course Code
PROG 10082

This preview shows page 1. to view the full 4 pages of the document.
Java Lecture 4
In the expressions examples slide, there's 3 variables.
mathematical methods functions are used to tell the computer how to calculate things,
such as Math.pow(x,y);
Math is a class, and the method is coming from the class, so in thix example Pow would
be the power class
-math.sqrt would give us the second root of a number, as in squared
-math.pow(8, 1/3)--> make sure to write the 1/3 as 1.0/3
Larger math expressions
double result=Math.sqrt((102.0+79.0-576.7)/3927.0);
System.out.println("%.2d, result);
Note that if you calculate the value of this expression, you get a negative value. There is
no way to find the second root of a negative value. We are finding the sqrt of a negative
number and java cant read it.
type casting changes the value of a variable to another, and it is not recommended unless
-implicit typecasting ex. 3, you cant change two variables at the same time-see slide
saying Example
Class Example: Find the average of two integers
age 1+ age 2/2 is the mathematical version
int age1=3;
int age 2=5;
*when you are dealing with division the result should be a floating point. because when
you have different numbers you need the right answer mathematically.
double avg;
two ways to change that are to change the 2 to 2.0 or to change the age1 and age2 to
doubles. At least one of the inputs must be a double so that the output can be a double
public class ProgramV
{ // The mathematical constant Pi // Note: 'static' is needed here to use it from main
private static double pi;
public static void main(String[] args)
{ // This writes a message to the screen
You're Reading a Preview

Unlock to view full version

Subscribers Only

Loved by over 2.2 million students

Over 90% improved by at least one letter grade.