i want the user input a string on void method, then uses a char method to find a random character from that particular string.
import java.util.*;
public class randch {
String paces;
char c;
void setpaces(String faces) {
Scanner input = new Scanner(System.in);
System.out.println("Set paces: ");
paces = input.next();
System.out.println(paces.length() + " characters");
}
char rolling(){
Random random = new Random();
for(int i = 0; i < paces.length(); i++) {
c=paces.charAt(i);
}
c = (char) random.nextInt();
System.out.println(c);
return c;
}
public static void main(String[] args) {
randch u = new randch();
u.setpaces(u.paces);
u.rolling();
}
}

New Topic/Question
Reply




MultiQuote



|