鱼C论坛

 找回密码
 立即注册
查看: 2529|回复: 1

[已解决]java

[复制链接]
发表于 2020-6-5 10:35:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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,数字顺序反了而且还多了个*,这要怎么改
最佳答案
2020-6-5 11:39:18

  1. import java.util.Scanner;

  2. public class test2 {
  3.     public static void main(String[] args) {
  4.         Scanner scan = new Scanner(System.in);
  5.         System.out.print("输入数字:");
  6.         int ss = scan.nextInt();
  7.         int div = 100000;
  8.         int temp;
  9.         int mul = 1;
  10.         while(div!=0) {
  11.             temp = ss / div;
  12.             ss %= div;
  13.             if(div == 1){
  14.                 System.out.print(temp + "=");
  15.             }else{
  16.                 System.out.print(temp + "*");
  17.             }
  18.             mul *= temp;
  19.             div /= 10;
  20.         }
  21.         System.out.print(mul);

  22.     }
  23. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-6-5 11:39:18 | 显示全部楼层    本楼为最佳答案   

  1. import java.util.Scanner;

  2. public class test2 {
  3.     public static void main(String[] args) {
  4.         Scanner scan = new Scanner(System.in);
  5.         System.out.print("输入数字:");
  6.         int ss = scan.nextInt();
  7.         int div = 100000;
  8.         int temp;
  9.         int mul = 1;
  10.         while(div!=0) {
  11.             temp = ss / div;
  12.             ss %= div;
  13.             if(div == 1){
  14.                 System.out.print(temp + "=");
  15.             }else{
  16.                 System.out.print(temp + "*");
  17.             }
  18.             mul *= temp;
  19.             div /= 10;
  20.         }
  21.         System.out.print(mul);

  22.     }
  23. }
复制代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 13:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表