Results 1 to 3 of 3
Thread: Weird output
- 02-27-2010, 05:20 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
Weird output
Hey, I'm having trouble with my output. My code has no problems as far as I can see, but here it is:
import java.lang.Math;
import java.util.Scanner;
/**
* @(#)Mastermind.java
*
* Mastermind application
*
* @author
* @version 1.00 2010/2/23
*/
public class Mastermind {
public static void Main(String[]args) {
int number;
int r1;
int r2;
int r3;
int r4;
int g1;
int g2;
int g3;
int g4;
int bulls;
int cows;
int guess;
final int SENTINEL = 0;
int retry = 1;
Scanner input = new Scanner(System.in);
do{
number = (int)(9999 * Math.random() + 0000);
r4 = number % 10;
number /= 10;
r3 = number % 10;
number /= 10;
r2 = number % 10;
number /= 10;
r1 = number % 10;
bulls = 0;
cows = 0; //determine the number and reset the bulls and cows
for (int turn = 1; turn <= 10; turn++) {
System.out.println("Turn " + turn); // tell the user what turn he is on
System.out.println("Please enter your guess (i.e. 1445): ");
guess = input.nextInt();
g4 = number % 10;
number /= 10;
g3 = number % 10;
number /= 10;
g2 = number % 10;
number /= 10;
g1 = number % 10; //evaluate the users guess into single digits
if (g1 == r1)
bulls++;
else if (g1 == r2 || g1 == r3 || g1 == r4)
cows++;
if (g2 == r2)
bulls++;
else if (g2 == r1 || g2 == r3 || g2 == r4)
cows++;
if (g3 == r3)
bulls++;
else if (g3 == r1 || g3 == r2 || g3 == r4)
cows++;
if (g4 == r4)
bulls++;
else if (g4 == r1 || g4 == r2 || g4 == r3)
cows++;
System.out.println("Number of bulls: " + bulls);
System.out.println("Number of cows: " + cows); //check the guess and tell the user how close he was
if (bulls == 4)
{
System.out.println("Code broken by trying " + turn + " times.");
turn = 10; //tell the user that he has won
}
else
{
bulls = 0;
cows = 0; //reset bulls and cows for next guess
}
if (turn == 10 && bulls != 4)
{
System.out.println("Failed to break the code. ");
System.out.println("The answer is: " + r1 + r2 + r3 + r4);
System.out.println("Enter 0 to quit, anything else to continue.");
retry = input.nextInt(); //tell the user he has lost and ask for a retry
}
}
} while (retry != SENTINEL);
}
}
:(
My output is:
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
-splash:<imagepath>
show splash screen with specified image
Process completed.
- 02-27-2010, 06:03 AM #2
Member
- Join Date
- Feb 2010
- Posts
- 75
- Rep Power
- 0
I had capitalized main in the class declaration.
FML
- 02-28-2010, 10:17 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 68
- Rep Power
- 0
Similar Threads
-
weird problem
By GPB in forum New To JavaReplies: 2Last Post: 02-28-2010, 01:04 PM -
Seriously weird output
By gandalf5166 in forum Java AppletsReplies: 4Last Post: 02-27-2010, 05:16 AM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-26-2009, 12:44 AM -
Weird Error?
By sciguy77 in forum New To JavaReplies: 4Last Post: 01-20-2009, 03:32 AM -
Weird data output
By Shaolin in forum New To JavaReplies: 12Last Post: 12-11-2007, 05:27 PM
Bookmarks