If it is for multiple guesses, then you can't keep giving a new value to lotteryNum each time through the loop.
Edit: Then it seems OK, except you need
String lotteryNum = "";
to be inside the loop.
Also, you could generate all 3 digits with:
String lotteryNum = "";
for (int i=0; i<3; i++) lotteryNum += (int) (Math.random () * 10);
I want a program that will generate a 3-digit number, each digit ranging from 0-9. Then ask the user to guess the number. I have to use a for loop and strings, not ints.
I'd appreciate a lot of someone checked my code. I confused on the for loop part where it's supposed to generate a 3 digit number, but I don't know if I even set it up right ;/
import java.util.Scanner;
public class Lottery
{
public static void main(String[] args)
{
//declare and initialized variables and objects
Scanner in = new Scanner(System.in);
String lotteryNum = "";
String userGuess = "";
double randNum;
int terminator = 9;
int randomNum;
for(int counter = 0; counter <= terminator; counter ++)
{
randomNum = (int)(Math.random() * 10);
lotteryNum += randomNum;
randomNum = (int)(Math.random() * 10);
lotteryNum += randomNum;
randomNum = (int)(Math.random() * 10);
lotteryNum += randomNum;
System.out.print("Please enter your three numbers (e.g. 123): "); //ask user to input their guess
userGuess = in.next();