public static void main(String[] args) { Hashtable hashtable = new Hashtable(); Random rm = new Random(); int RmNum = 10; for (int i = 0; hashtable.size() < RmNum; i++) { int nValue = rm.nextInt(100); if (!hashtable.containsValue(nValue) && nValue != 0)// 去重 { hashtable.put(nValue, nValue); } } System.out.println(hashtable.values()); } } ---------------------------------------------------- import java.lang.reflect.Array; import java.util.Random;
public class Lottal { private int num; private int length; private int[] array; public Lottal(int num, int length) { this.num = num; this.length = length; } public void getRandom() { Random rnd = new Random(); array = new int[length];
for (int i = 0; i < length; i++) { int rndNum = rnd.nextInt(num + 1); array[i] = rndNum; System.out.println(array[i]); } } public String getLottalResult() {
for (int i = 0; i < num - 1; i++) { System.out.println(); } return array.toString(); } public static void main(String[] args) { Lottal lottal = new Lottal(3, 3); lottal.getRandom(); } }
--------------------------------- Hashtable hashtable = new Hashtable(); Random rm = new Random(); int RmNum = 100; for (int i = 0; hashtable.Count < RmNum; i++) { int nValue = rm.Next(100); if (!hashtable.ContainsValue(nValue) && nValue != 0)//去重 { hashtable.Add(nValue, nValue); Console.WriteLine(nValue.ToString()); } } ----------------------------------
import java.util.Random;
public class testRandom {
public static void main(String[] args) { Random test = new Random(); int[] a = new int[10]; int index; for (index = 0; index < a.length; index++) { a[index] = index + 1; } index--; int tempIndex, tempContent; for (; index >= 0; index--) { tempIndex = test.nextInt(a.length); tempContent = a[index]; a[index] = a[tempIndex]; a[tempIndex] = tempContent; }
for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } }
---------------------------------- args[]
1.Scanner s = new Scanner(System.in); int i = s.nextInt(); 2. BufferedRader b = new BufferedReader(new InputStreamReader(System.in));
public class Tongxuelu { public static void main(String[] arg) throws Exception { String name2; String phonenumber; for (int a = 0; a < 5; a++) { System.out.println("请输入你的名字"); BufferedReader name1 = new BufferedReader( new InputStreamReader(System.in)); name2 = name1.readLine(); System.out.println("请输入你的电话号码");