public void randomGen(String[] x) {
int rand = rangen.nextInt(x.length-2);
JOptionPane.showMessageDialog(null, "Randomly chosen word is: " + x[rand]);
}
For anyone...
Type: Posts; User: Blackrabbitjack
public void randomGen(String[] x) {
int rand = rangen.nextInt(x.length-2);
JOptionPane.showMessageDialog(null, "Randomly chosen word is: " + x[rand]);
}
For anyone...
Would this be the proper way to use this utility?
public void randomGen(String[] x) {
Random rangen = new Random();
int rand = rangen.nextInt(x.length-1);
}
Not too sure if this is the right place to post this, so if it isn't, I apologize. Still figuring out my way around here.
Anyways, what is the best way to grab a random element from an array?...
Welcome! I'm fairly new to these forums as well, and am approximately at the same level of programming capabilities as you are. Been toying with java in a lot of my college courses over the years. If...
I will agree with Norm. If you only need a quick variable for a function inside a method, instantiate it within the method. Otherwise, if you need multiple methods to use a single variable, or a...
I was confused by what Norm is trying to say when he posted it in my post. Basically, whenever you want to see if a variable is being assigned to something, use a println to say ("Assigned variable...
Jumping the gun on trying to make the GUI is always a bad idea. Make your methods work and your logic correct before you try to make it look pretty. What compiler are you using? Also, it might be...
varlib.tableA[i] = readIn;
Stupid mistake, but the code works. Thanks for pointing me in the right direction!
public void popTableAArray() {
String readIn;
try{
BufferedReader br = new BufferedReader(new FileReader("tableA.txt"));
System.out.println("For...
public void popTableAArray() {
String readIn;
try{
BufferedReader br = new BufferedReader(new FileReader("tableA.txt"));
for(int i=0;...
Placed the file in the root directory, and changed the println to show the values of readIn. Still outputs my Else first, and still shows the values of the txt file as null. There are no other files...
You're asking the wrong guy. What are you talking about "where the null file is?" Would it not show a IO Error if it loaded a file that doesn't exist? My pathing is entirely correct. I'll try putting...
This code:
public void popTableAArray() {
String readIn;
try{
BufferedReader br = new BufferedReader(new FileReader("db/tableA.txt"));
for(int i=0;...
There is only one text file in the specified directory. It's formatted as such
Sleeping
Tired
Hungry
....
(those are the actual first three lines of the file) Is there something crucial I'm...
The oracle document states that reader will return:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
...
Alright, I've been plugging away at this code for quite some time. I finally felt it necessary to seek assistance in an online forum, as my JAVA mentor is away for the time being.
My idea is to...