public static void main(String[] args){
// TODO Auto-generated method stub
put(3);
numToString(56576898);
System.out.println("\n"+stringMulti("233","45"));
}
/**
* 把数字转化成中文描述,比如12330453
* 转化成:一千二百三十三万零四百五三
*/
public static void numToString(int N){
if(N<0 && N>=100000000){
System.out.println("数值大小出界!");
}
if(N==0){
System.out.println(numToChinese(N));
return;
}
int wan=N/10000;
int qian=N%10000;
if(wan!=0){
fourNumToString(wan);
System.out.print("万");
}
fourNumToString(qian);
}
private static void fourNumToString(int N_4){
if(N_4>=10000){
System.out.println("Error! Number bigger than 9999");
}
int[] num=new int[4];
int i=3;
while(N_4!=0){
num[i--]=N_4%10;
N_4/=10;
}
for(int j=i+1;j<4;j++){
if(j==0){
System.out.print(numToChinese(num[j])+"千");
int flag=0;
for(int k=j+1;k<4;k++){
if(num[k]!=0) flag=1;
}
if(flag==0) break;
}else if(j==1){
if(num[j]==0){
System.out.print(numToChinese(num[j]));
}else{
System.out.print(numToChinese(num[j])+"百");
int flag=0;
for(int k=j+1;k<4;k++){
if(num[k]!=0) flag=1;
}
if(flag==0) break;
}
}else if(j==2){
if(num[j]==0){
if(num[j-1]!=0){
System.out.print(numToChinese(num[j]));
}
}else{
System.out.print(numToChinese(num[j])+"十");
int flag=0;
for(int k=j+1;k<4;k++){
if(num[k]!=0) flag=1;
}
if(flag==0) break;
}
}else if(j==3){
System.out.print(numToChinese(num[j]));
}
}
}
private static String numToChinese(int n){
switch (n){
case 0:return "零";
case 1:return "一";
case 2:return "二";
case 3:return "三";
case 4:return "四";
case 5:return "五";
case 6:return "六";
case 7:return "七";
case 8:return "八";
case 9:return "九";
default:return "";
}
}
/**
* 笔试算法题,如输入整数n,按如下方式输出矩阵。设N=4,为
* 1, 2, 6, 7
* 3, 5, 8, 13
* 4, 9, 12,14
* 10,11,15,16
*/
public static void put(int N){
if(N<=0)
return;//如果输入的数据小于等于0,do nothing
int[][] tmp=new int[N][N];//存储矩阵
int i=0,j=0,k=1;
int flag=0;//标记方向,控制数值增加的转向
while(!(i==N-1&&j==N-1)){
if(i==0 && j==0) {
tmp[i][j++]=k++;
flag=1;
continue;
}//起始方向
if(i==0 && flag==1){//上边界反弹
while(j!=0 && i!=N-1){
tmp[i++][j--]=k++;
}
flag=0;
continue;
}else if(i==0 && flag==0){
if(j<N-1){
tmp[i][j++]=k++;
}else{
tmp[i++][j]=k++;
}
flag=1;
continue;
}
if(flag==1 && j==0){//左边反弹
while(j!=N-1 && i!=0){
tmp[i--][j++]=k++;
}
flag=0;
continue;
}else if(flag==0 && j==0){
if(i<N-1){
tmp[i++][j]=k++;
}else{
tmp[i][j++]=k++;
}
flag=1;
continue;
}
if(flag==1 && j==N-1){//右边界反弹
while(j!=0 && i!=N-1){
tmp[i++][j--]=k++;
}
flag=0;
continue;
}else if(flag==0 && j==N-1){
tmp[i++][j]=k++;
flag=1;
continue;
}
if(i==N-1 && flag==1){//下边反弹
while(j!=N-1 && i!=0){
tmp[i--][j++]=k++;
}
flag=0;
continue;
}else if(i==N-1 && flag==0){
tmp[i][j++]=k++;
flag=1;
continue;
}
}
tmp[N-1][N-1]=k;
System.out.println("输入为"+N+",输出矩阵如下:");
for(int m=0;m<N;m++){
for(int n=0;n<N;n++)
System.out.printf("%-8d", tmp[m][n]);
System.out.println();
}
};
/**
* 将输入的两个字符串数字相乘,返回结果字符串
*/
public static String stringMulti(String num1,String num2){
int aNum1=Integer.parseInt(num1);
int aNum2=Integer.parseInt(num2);
int num=aNum1*aNum2;
return ""+num;
}