+ -
当前位置:首页 → 问答吧 → Random method (Maths Class)

Random method (Maths Class)

时间:2009-03-24

来源:互联网

An International Number Generating Department has decided to generate all car number plates as follows:
* three random uppercase characters followed by three random digits (Eg: NLF810)
Write an application called GenerateNumberPlate, which generates a number plate for a car registered in your country. Use the random method from the Maths Class.

我应该怎样做, 可以打出来让我参考一下吗

作者: Kavan0922   发布时间: 2009-03-24

为什么要做这个?

作者: chih0812   发布时间: 2009-03-24

chih0812 wrote:
为什么要做这个?

这是我大学 学JAVA课的 Exercise之一,
但是我不明白可以怎样做, 字母和数字可以怎样一起RANDOM

作者: Kavan0922   发布时间: 2009-03-24

在 java.util 套件中有一个 Random 类别有提供 nextInt(int n) 会传回 0-n 之间的整数

作者: 神領菜刀   发布时间: 2009-03-24

神领菜

作者: Kavan0922   发布时间: 2009-03-25

1
2
3
4
5
6
Random r=new Random(); // 使用类别要先产生物件实体
char[] c=new char[3]; // 宣告要放3个大写英文字母
for(int i=0;i<c.length;i++){ // 你的题目要产生3个英文字母,所以回圈做3次 c[i]=(char)('A'+r.nextInt(25)); // r.nextInt(25)) 会传回 0-25 ,'A'+0='A' ... 'A'+1='B' ... 'A'+25='Z'
}
System.out.println(new String(c)+r.nextInt(999));

作者: 神領菜刀   发布时间: 2009-03-25

神领菜

作者: Kavan0922   发布时间: 2009-03-25

神领菜

作者: TIDUS30536   发布时间: 2011-12-22

热门下载

更多