我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*fileName:P5Q20
* Name:Wang Chaoran
* Description:
20 (Generating random characters)
Use the methods in RandomCharacter in Listing 5.6 to print one hundred uppercase letters and then one hundred single digits, and print ten per line.
*/
public class P5Q20{
public static void main(String[] args){
System.out.println("One hundred uppercase letters :");
for(int i=0;i<100;i++){
if(i%10==9)
System.out.println(getRandomCharacter('A','Z')+" ");
else
System.out.print(getRandomCharacter('A','Z')+" ");
}
System.out.println("\nOne hundred single digits :");
for(int i=0;i<100;i++){
if(i%10==9)
System.out.println(getRandomCharacter('1','9')+" ");
else
System.out.print(getRandomCharacter('1','9')+" ");
}
}
public static char getRandomCharacter(char ch1, char ch2){
return (char)((int)(ch1)+Math.random()*((int)(ch2)-(int)(ch1)+1));
}
}
导入论坛查看(28)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing