入力した数字を大文字にする
要求:入力した数字を大文字に変えて、数字の入力は8桁を超えることができません
package com.wansha;
public class NumberTest {
public String formateNubmer(String str)throws Exception{
String sum = "";
Integer in = 0;
try{
in = Integer.parseInt(str);
}catch(NumberFormatException e){
throw new Exception(" ");
}
String bitStr = "";
boolean flag = false;
for(int i = 0; i<str.length();i++){
int Remainder = in%10;
in/=10;
if(Remainder == 0){
if(!flag)continue;
bitStr =changeUpperCase(Remainder);
flag = false;
}else{
switch(i){
case 0:
bitStr = changeUpperCase(Remainder);
flag = true;
break;
case 1:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
case 2:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
case 3:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
case 4:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
case 5:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
case 6:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
case 7:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
case 8:
bitStr = changeUpperCase(Remainder)+" ";
flag = true;
break;
}
}
sum = bitStr +sum;
}
sum = sum.endsWith(" ")?sum.substring(0,sum.indexOf(" ")):sum;
sum = sum.startsWith(" ")?sum.substring(sum.indexOf(" ")+1):sum;
return sum;
}
public static void main(String[] args)throws Exception {
args[0]="00000100";
int k = Integer.parseInt(args[0]);
if(null != args[0]){
if(8<args[0].length())throw new Exception(" 8 ");
NumberTest number = new NumberTest();
String sum ;
sum = number.formateNubmer(args[0]);
System.out.println(sum);
}
}
public String changeUpperCase(int i){
String str = null;
switch(i){
case 0:
str=" ";
break;
case 1:
str=" ";
break;
case 2:
str=" ";
break;
case 3:
str=" ";
break;
case 4:
str=" ";
break;
case 5:
str=" ";
break;
case 6:
str=" ";
break;
case 7:
str=" ";
break;
case 8:
str=" ";
break;
case 9:
str=" ";
break;
}
return str;
}
}