我有一个程序&我不会随机读取ARRAY我没有程序错误但在输出期间我有空值我能给你解决方案...
import java.io.FileInputStream;
import java.util.Properties;
import java.util.Random;
import javax.swing.JOptionPane;
public class ReadDB {
public static void main(String[] args) {
Properties prob = new Properties();
String word [] = new String [20] ;
try{
prob.load( new FileInputStream("words.txt"));
}catch(Exception e){
}
for(int i=1; i<6; i++){
String temp = prob.getProperty(""+i);
word[i] = temp;
Random ran = new Random ();
String Val = word[ran.nextInt(word.length)];
System.out.println(Val);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
192 次 |
| 最近记录: |