Computer Science 15-110 (Lecture 4), Spring 2010
Homework 1 Practice
Due: Never. This is not
assigned work.
Read these instructions first!
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); System.out.print("Enter a 3-digit integer (between 100 and 999): "); // You may assume the user enters a number in the desired range. int x = scanner.nextInt(); int a = x%10; int b = (x/10)%10; int c = x/100; int d = 100*a + 10*b + c; System.out.println(d); } }
Carpe diem!