import java.util.Scanner;
public class Test1 {
static int i=0;
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入a:");
int a=sc.nextInt();
System.out.println("请输入b:");
int b=sc.nextInt();
System.out.print("a*b结果为:");
int result=starMul(a,b);
System.out.println(result);
}
private static int starMul(int a,int b) {
int s=0;
while(a!=1){
if(a%2==1){
i++;
s=s+b;
b=b*2;
a=(a-1)/2;
}else{
i++;
b=2*b;
a=a/2;
}
}
return s+b;
}
兄弟在么?写好了!那去吧!自己多看看啊,以后不会再来问我把!