JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//enter name [enter] o/e(odd/even) [enter] fingers(0-5)[submit]
import java.util.*;
public class oddeven {
public static void main(String[] args) {
Scanner input= new Scanner(System.in);
Random rand=new Random();
System.out.println ("Let’s play a game called Odds and Evens");
System.out.println("What is your name?");
String name= input.nextLine();
System.out.println("Hi "+name+", which do you choose? (O)dds or (E)vens?");
String choice=input.nextLine();
if(choice.equalsIgnoreCase("O"))
System.out.println(""+name+" has picked odds! The computer will be evens.");
else if(choice.equalsIgnoreCase("E"))
System.out.println(""+name+" has picked evens! The computer will be odds.");
System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _");
System.out.println("How many fingers do you put out?");
int user=input.nextInt();
int comp=rand.nextInt(6);
System.out.println("The computer plays "+comp+ " fingers.");
System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _");
int sum=comp+user;
System.out.println(user+" + "+comp+" = "+sum);
{
if (sum % 2 == 0 && choice.equalsIgnoreCase("E")) {
System.out.println(sum + " is ...even");
System.out.println("That means " + name + " wins! :)");
} else if (sum % 2 == 1 && choice.equalsIgnoreCase("O")) {
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run