{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

L05 - Computer Science 1 1 SS C Lecture 5 Contents > java...

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

View Full Document Right Arrow Icon
CS101 Lecture 5 1 Computer Science 1 1 SS C Lecture 5 Contents Order of operations in expressions Using static methods An introduction to String objects Obtaining input from the user Converting a String into an int Converting a String into a double Coursebook: parts of §6, §7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Review public class Review { public void start() { } } amount = amount + 20; balance = 500.5 + amount; amount = 435; double balance; leftOvers = amount % 100; int amount, leftOvers; System.out.print("Deposit $"); System.out.println(amount); System.out.print("Current balance $"); System.out.println(balance); System.out.println(leftOvers); > java ReviewApp Deposit $455 Current balance $955.5 35 3 1 2 3 4 5 6 7 8 9 10 Review - What is the output? public class MyProgram { public void start() { int numberOfSeconds = 130 ; int numberOfMinutes = numberOfSeconds / 60; numberOfSeconds = numberOfSeconds % 60; System.out.print(numberOfMinutes); System.out.print(":"); System.out.println(numberOfSeconds); } } converting seconds to minutes and seconds 2:10 4 Order of precedence What do the following expressions evaluate to? 23 35 2 3 + 4 * 5 (3 + 4) * 5 3 * 4 / 5 5 Order of precedence • highest precedence operators are always evaluated first • if operators have the same precedence, then evaluation is from left to right The evaluation of expressions follows these two rules: This table summarises the precedence of all the operators: 6 Converting between types . 23 23 0 int num1 = 23; double num2; num2 num1 What will happen? num2 = num1; This is called "widening"
Background image of page 1

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

View Full Document Right Arrow Icon
CS101 Lecture 5 2 7 Converting between types . 5 6 int num3; double num4 = 5.6; num4 num3 What will happen? num3 = num4; Implicitly converting between compatible types 45 45.0 int double no information is lost when this widening conversion takes place. For example: Widening conversion: Data of a given numeric type can always be converted to a "wider" type.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}