1.汉字数字
import java.util.Scanner;
public class Homework1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你要转换的金额:");
int i = scanner.nextInt();
String[] shuzi = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
String[] danwei = { "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "十" };
String string = i + "";
char[] cs = string.toCharArray();
String printStr = "";
for (int j = 0; j < cs.length; j++) {
int index = cs[j] - 48;
if (shuzi[index] == "壹" && cs.length == 6) {
shuzi[index] = "";
printStr = printStr + shuzi[index];
} else {
printStr = printStr + shuzi[index];
}
printStr = printStr + danwei[cs.length - j - 1];
}
}
}
2.模拟斗地主发牌
import java.util.Random;
public class Homework2 {
public static void main(String[] args) {
String[] colors = { "♠", "♥", "♣", "♦" };
String[] numbers = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
String[] Kings = { "大王", "小王" };
String[] pooker = new String[colors.length * numbers.length + Kings.length];
int index = 0;
for (int i = 0; i < colors.length; i++) {
for (int j = 0; j < numbers.length; j++) {
pooker[index] = colors[i] + numbers[j];
index++;
}
}
pooker[pooker.length - 1] = Kings[0];
pooker[pooker.length - 2] = Kings[1];
for (int i = 0; i < pooker.length; i++) {
System.out.println(pooker[i]);
}
String[] play1 = new String[17];
String[] play2 = new String[17];
String[] play3 = new String[17];
String[] dizhu = new String[3];
Random random = new Random();
for (int i = 0; i < 17; i++) {
int j = random.nextInt(pooker.length);
if (pooker[j] == null) {
i--;
continue;
} else {
play1[i] = pooker[j];
pooker[j] = null;
}
}
for (int i = 0; i < 17; i++) {
int j = random.nextInt(pooker.length);
if (pooker[j] == null) {
i--;
continue;
} else {
play2[i] = pooker[j];
pooker[j] = null;
}
}
for (int i = 0; i < 17; i++) {
int j = random.nextInt(pooker.length);
if (pooker[j] == null) {
i--;
continue;
} else {
play3[i] = pooker[j];
pooker[j] = null;
}
}
for (int i = 0; i < 3; i++) {
int j = random.nextInt(pooker.length);
if (pooker[j] == null) {
i--;
continue;
} else {
dizhu[i] = pooker[j];
pooker[j] = null;
}
}
for (int i = 0; i < play1.length; i++) {
System.out.print(play1[i] + "\t");
}
System.out.println();
for (int i = 0; i < play2.length; i++) {
System.out.print(play2[i] + "\t");
}
System.out.println();
for (int i = 0; i < play3.length; i++) {
System.out.print(play3[i] + "\t");
}
System.out.println();
for (int i = 0; i < dizhu.length; i++) {
System.out.print(dizhu[i] + "\t");
}
}
}