Computer Science 15-100 (Lecture 18), Spring 2009
Homework 1 Practice
Due: Never. This is not
assigned work.
| a) |
public static void main(String[] args) {
int x = 5, y = 2, z = 3;
System.out.println(x + y * z);
System.out.println(x % y % z);
System.out.println(10 + 9 / x * z - y);
}
|
| b) |
public void paint(Graphics page) {
int c = getWidth(), d = getHeight();
page.fillRect(c/2-10, 50, 20, 100);
page.fillOval(c/4,d*3/4,c*3/4, d/4);
}
|
// Mystery code
import java.util.Scanner;
class MyCode {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// You may assume the user enters two positive integers.
System.out.print("Enter a positive integer: ");
int x = scanner.nextInt();
System.out.print("Enter another positive integer: ");
int y = scanner.nextInt();
int mystery = (x % 2) * (y % 2);
System.out.println(mystery);
}
}
(larger
image with details)
(larger
image with details)Carpe diem!