Hi,
For my program (dunno if you'd call it a program really yet ) I want to create a 'Do you want to Continue sort of thing incorporating a while loop to redo it, but because the interger will already have been defined there's an error in compilation. How can I tell Java to redefine/overwrite the number so this'll work? This is the code.
import java.util.Scanner; import java.io.File; import java.io.IOException; public class ChoiceofRandomNumberwithPeople { public static void main(String[] args) throws IOException { Scanner r = new Scanner(System.in); Scanner l = new Scanner(System.in); Scanner p = new Scanner(System.in); Scanner q = new Scanner(System.in); System.out.println("Ok! Enter 4 People"); String firstname = r.nextLine(); String secondname = l.nextLine(); String thirdname = p.nextLine(); String fourthname = q.nextLine(); int aNumber = 0; { int myRandom = (int) ((Math.random()) * 4); while (aNumber < 2) if((int)(myRandom) == 1) { System.out.println(firstname); System.out.println("Do you want another Random Person?"); int aNumber = r.nextInt(); } if((int)(myRandom) == 2) { System.out.println(secondname); System.out.println("Do you want another Random Person?"); int aNumber = r.nextInt(); } if((int)(myRandom) == 3) { System.out.println(thirdname); System.out.println("Do you want another Random Person?"); int aNumber = r.nextInt(); } if((int)(myRandom) == 4) { System.out.println(fourthname); System.out.println("Do you want another Random Person?"); int aNumber = r.nextInt(); } } } }
Thanks for your help.