Computer Science 225
Advanced Programming
Spring 2020, Siena College
Lecture 2: Java You Know
Date: Friday, January 24, 2020
Agenda
- Announcements
- Lab 0: Setting Up and Refresher due at the start of your lab next week
- Problem Set 1 due next Wednesday night
- Input/output redirection for Lab 0 and Problem Set 1
- Git and GitHub workflow
- GitHub Issues mechanism for Problem Set 1 submissions
- Some Java You Know
- In-class exercises (5 assignment points)
- Draw a memory diagram for the
StaticStuff example when the main
method is about to complete execution.
- Rewrite the switch statement in the code segment below
with if and else statements:
Scanner kbd = new Scanner(System.in);
System.out.print("Enter a number 1-10: ");
int number = kbd.nextInt();
switch (number) {
case 1:
case 4:
case 6:
case 8:
case 9:
case 10:
System.out.println(number + " is composite.");
break;
case 2:
case 3:
case 5:
case 7:
System.out.println(number + " is prime.");
break;
default:
System.out.println(number + " is out of the allowed range (1-10)");
break;
}
- Rewrite the for loop below as an enhanced for loop,
where a is an ArrayList<Integer>:
for (int i = 0; i < a.size(); i++) {
int x = a.get(i);
// do something with x
}
Examples