/* * Dan Williams * CS100M and the rest of the header... */ public class Task1{ public static void main(String args[]){ int maxrolls = 100000; int snakeeyes = 0; int die1, die2; for(int count = 0; count < maxrolls; count++){ die1 = (int)Math.floor(Math.random()*6)+1; die2 = (int)Math.floor(Math.random()*6)+1; if ((die1 + die2) == 2) snakeeyes++; } System.out.println("Chance of snake-eyes: " + ((double)snakeeyes/maxrolls)*100 + "%"); } } /* * Dan Williams * CS100M and the rest of the header... */ public class Task2{ public static void main(String args[]){ System.out.print("Enter a number: "); int num1 = SavitchIn.readInt(); System.out.print("Enter another number: "); int num2 = SavitchIn.readInt(); for(int i = Math.min(num1, num2); i <= Math.max(num1, num2); ++i){ if ((i % 2) == 0) System.out.println(i); } } } /* * Joseph Chiu * CS100M - E8 Solutions */ public class Task3{ public static void main(String args[]){ int depth = 0; do{ System.out.print("Enter a number: "); depth = SavitchIn.readInt(); } while (depth <= 1); for (int row = 1; row <= depth; row++){ for (int col = 1; col <= depth+row+1; col++){ if (col <= depth-row) System.out.print(" "); else System.out.print("*"); } System.out.print("\n"); } } }