Class Notes (974,329)
CA (573,877)
PROG 10082 (10)
Dancy (10)
Lecture 4

# PROG 10082 Lecture 4: Java Lecture 4 Premium

by OneClass766106 , Winter 2016
4 Pages
95 Views
Winter 2016

Department
Computer Engineering Technology
Course Code
PROG 10082
Professor
Dancy
Lecture
4

This preview shows page 1. Sign up 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
mandatory
-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;
avg=(age1+age2)/2;
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
method
private static double pi;
public static void main(String[] args)
{ // This writes a message to the screen

#### Loved by over 2.2 million students

Over 90% improved by at least one letter grade.

OneClass has been such a huge help in my studies at UofT especially since I am a transfer student. OneClass is the study buddy I never had before and definitely gives me the extra push to get from a B to an A!

Leah â€” University of Toronto

Balancing social life With academics can be difficult, that is why I'm so glad that OneClass is out there where I can find the top notes for all of my classes. Now I can be the all-star student I want to be.

Saarim â€” University of Michigan

As a college student living on a college budget, I love how easy it is to earn gift cards just by submitting my notes.

Jenna â€” University of Wisconsin

OneClass has allowed me to catch up with my most difficult course! #lifesaver

Anne â€” University of California
Description
Java Lecture 4 In the expressions examples slide, theres 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, 13)> make sure to write the 13 as 1.03 Larger math expressions double result=Math.sqrt((102.0+79.0576.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 mandatory implicit typecasting ex. 3, you cant change two variables at the same timesee slide saying Example Class Example: Find the average of two integers age 1+ age 22 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; avg=(age1+age2)2; 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 method private static double pi; public static void main(String[] args) { This writes a message to the screen
More Less

Only page 1 are available for preview. Some parts have been intentionally blurred.

Unlock Document

Unlock to view full version

Unlock Document

# You've reached the limit of 4 previews this month

Create an account for unlimited previews.

Notes
Practice
Earn
Me

OR

Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Join to view

OR

By registering, I agree to the Terms and Privacy Policies
Just a few more details

So we can recommend you notes for your school.