package studying3;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
while(true){
System.out.println("请输入一个字符串:");
str = sc.next();
boolean flag = judge(str);
if(flag){
System.out.println("请继续操作~");
break;
}else{
System.out.println("格式不正确,请重新输入:");
}
}
//将char c中的c转换成字符串
StringBuilder sb = new StringBuilder();
for(int i =0;i<str.length();i++){
char c = str.charAt(i);
int number = c - 48;
//System.out.println(number);
String result = toRome(number);
sb.append(result);
}
String res = sb.toString();
System.out.println(res);
}
public static String toRome(int number){
String[] arr = new String[]{"","Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ","Ⅸ"};
return arr[number];
}
public static boolean judge(String str) {
if (str.length() > 9) {
return false;
}
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (c < '0' || c > '9') {
return false;
}
}
return true;
}
}
02-06
594
594

被折叠的 条评论
为什么被折叠?



