Escolar Documentos
Profissional Documentos
Cultura Documentos
public static void main (String []args){ (start main method with this)
Scanner object;
import java.util.Scanner; \\ tells java to scan, put before class declaration statement
Scanner scan = new Scanner(System.in) \\ standard method for creating a new scanner method. You can replace 'scan'
with whatever you want though
while (scan.hasNextInt()){
int aNumber = scan.nextInt(); \\ puts the int value scanned into the variable 'aNumber'
} \\ this creates a while loop to scan for ints in a file called 'myNumbers'
Scanner s = new Scanner(input); \\ this scans a string, then letting you specify what to look for
hasNextInt() \\ will return the next int you scan, and is a boolean (thus if the next int you scanned is the one you're
looking for, as specificed by your other parameters, then it returns true, otherwise it returns false. This is used for
setting up loops, as per above. Note that both methods can be used for things other than Int (hasNext and next by
themselves return strings, you can then specify what to look for by adding String pattern, pattern being what you're
looking for), for example nextDouble or nextFloat
int numbers; \\ setup and other stuff occurs here, see above for details
while (Numbers <= 10000){ \\ this is your while loop, where you state the expression to be evaluated
Numbers = Numbers + 100; \\ executes ( and loops) this statement while the expression is true
if (Numbers < 9001) { \\ sets up a conditional if statement that loops while true
count++; \\ increments count (you can also write it as "count = count + 1; ''
System.out.println ("You lost the game" + count + " times"); \\ also does this
} else if (int >= 9000) { \\ another if statement, but executes preceding statement is false
System.out.println ("You won the game forever" + count + " times"); \\ does this
System.out.println ("Magnetics, they are equal to: " + count + " times"); \\ does this
}
}
Scanner keyboard = new Scanner (System.in); \\ create scanner called 'keyboard' to register user input
Random object;
Random whatever = new Random(); \\ declaring a new random generator called 'whatever'
int/double nubsauce = whatever.nextInt/Double(); \\ the number inside the brackets dictates how many numbers are
generated, zero (0) inclusive