CS 145 Lecture 2 – More data, more instructions
Agenda
- what does this do?
- literals vs. variables
- a few more types (int, char, boolean)
- penny RAM
- a few more instructions (cos, pow)
Javadoc- String
What does this do?
- int a = 7;
int b = 3;
b = a + b; - int i;
System.out.println(i); - int i = 100;
System.out.println(i / 0);
Code
Day2.java
package preexam1;
public class Day2 {
public static void main(String[] args) {
double myNum = 6.7;
int brettsFavoriteNumber = 9;
char debrasFavoriteLetter = 'd';
boolean isNickAPackersFan = false; // true
// float foo;
// long bigNumber;
// short smallNumber;
// byte aReallySmallNumber;
int l1 = (int) 13.6;
int l2 = (int) 23.0;
// int foo = 92384920348203948230942309;
System.out.println("A really big int:");
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);
System.out.println(l1);
// double h = square root of l1 squared + l2 squared;
// double h = Math.sqrt(0.0 / 0.0);
String label = "The hypotenuse:";
System.out.println(label);
double h = Math.sqrt(l1 * l1 + l2 * l2);
System.out.println(h);
int nSiblings = 1;
String gavInfo = "Gavin has " + nSiblings + " siblings";
System.out.println(gavInfo);
}
}
Prelab
Please sign up for an account at Practice-It. Sign up under UWEC, and add CS 145 as one of your courses. Before 8 AM on Monday, complete:
- Self-check 2.4
- Self-check 2.8
- Exercise 2.1
No credit will be given after 8 AM.
Haiku
Strings, celebrities!
They’re always getting quoted
They’re sure characters
They’re always getting quoted
They’re sure characters