java
import java.util.Scanner;public class timu2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("输入数字:");
int ss = scan.nextInt();
int f = ss%10;
int mul = 1;
while(ss!=0) {
mul *= f;
System.out.print(f+"*");
ss = (ss -f)/10;
f = ss%10;
}
System.out.println("="+mul);
}
}
题目:程序运行时通过键盘输入一个6位数,假设用户输入的数字为“654327”,则显示的答案为“6*5*4*3*2*7=5040”。编写一个程序,实现这样的功能:把每位上的数字相乘,求出它们的乘积。
我的原程序输出是7*2*3*4*5*6*=5040,数字顺序反了而且还多了个*,这要怎么改
import java.util.Scanner;
public class test2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("输入数字:");
int ss = scan.nextInt();
int div = 100000;
int temp;
int mul = 1;
while(div!=0) {
temp = ss / div;
ss %= div;
if(div == 1){
System.out.print(temp + "=");
}else{
System.out.print(temp + "*");
}
mul *= temp;
div /= 10;
}
System.out.print(mul);
}
}
页:
[1]