package three;
/*
* 字符操作
* 特殊乘法
* 写个算法对于两个小于1000000000的输入,求特殊乘法的结果
* 特殊乘法举例:123*45 = 1*4+1*5+2*4+2*5+3*4+3*5;
*
* */
import java.util.Scanner;`
public class Test1 {
public static void main(String[] args) {
String str1,str2;
Scanner scan = new Scanner(System.in);
//已字符串形式接收数字
System.out.print("为str1赋值: ");
str1 = scan.next();
System.out.print("为str2赋值: ");
str2 = scan.next();
//将str1 str2 转换为字符型数组
//使用toCharArry()方法
char[] ch1 = str1.toCharArray();
char[] ch2 = str2.toCharArray();
int num = 0;
for(int i =0;i<ch1.length;i++){
for(int j =0;j<ch2.length;j++){
//参与运算的是数字对应的ASCII码值
num +=((ch1[i]-'0')*(ch2[j]-'0'));
}
}
System.out.println("特殊乘法的值num="+num);
}
}
附上ASCII码值(部分截取)