This code uses the Random class to generate a random number up to 100.
You can change the 100 value to any interger you wish.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
This code uses the Random class to generate a random number up to 100.
You can change the 100 value to any interger you wish.
Please use [highlight=Java] code [/highlight] tags when posting your code.
Forum Tip: Add to peoples reputationby clicking the
button on their useful posts.
PHP Code:
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package unogame;
import java.util.*;
import java.lang.*;
import java.awt.*;
/**
*
* @author Xyn
*/
public class UNOGame {
static int ar;
int counter=0;
static int winCount= 0;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Welcome to Under or Over game. Your opponnents number will be displayed and you have to go over or under it.");
for(int i=1; i<6; i++) {
double cop = new Random() .nextInt(100) +1;
double plp = new Random() .nextInt(100) +1;
System.out.println(" The computers number is " + cop + " .") ;
Scanner keyboard = new Scanner(System.in);
String pick = keyboard.next();
unofile uno = new unofile();
if (pick.equals("over")) {
if (cop>plp) {
System.out.println("You win that round!");
winCount++;
}}
if (pick.equals("under")) {
if (cop<plp) {
System.out.println("You lose that round!");
}}
if (pick.equals("over")) {
if (cop<plp) {
System.out.println("You win that round!");
winCount++;
}}
if (pick.equals("under")) {
if (cop>plp) {
System.out.println("You lose that round!");
}}
System.out.print("Your number was ");
System.out.print(plp + "." );
}
unofile uno = new unofile();
uno.counterWin = winCount;
uno.writeWall();
}
}
Theres a sample of it in use. ((NOTE: POORLY CONSTRUCTED PROGRAM)