dxsyy 2024-10-01 16:01 采纳率: 50%
浏览 12
已结题

Java代码到底是哪里出错呀,代码甚至连整数都输出不出来


mport java.util.Scanner;
public class LITI {
    public static void main(String[] args){
        Scanner scanner=new Scanner(System.in);
        int n= scanner.nextInt();
        int ones =n%10;
        int tens = (n/10)%10;
        int hundreds = (n/100)%10;
        int thousands = n/1000;
        int onescube=ones*ones*ones;
        int tenschbe=tens*tens*tens;
        int hundredscube=hundreds*hundreds*hundreds;
        int thousandscube=thousands*thousands*thousands;
        int sum=onescube+tenschbe+hundredscube+thousandscube;
        System.out.println("sum");
    }
}

为什么输入1234,想求出各个数位上的数的立方和100,却输出2253.20呀

  • 写回答

10条回答 默认 最新

  • 路漫漫,其修远兮 2024-10-01 16:56
    关注

    他们都是人机别问了

    你试试我这个

    import java.util.Scanner;
    
    public class LITI {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            int ones = n % 10;
            int tens = (n / 10) % 10;
            int hundreds = (n / 100) % 10;
            int thousands = n / 1000;
            int onesCube = ones * ones * ones;
            int tensCube = tens * tens * tens;
            int hundredsCube = hundreds * hundreds * hundreds;
            int thousandsCube = thousands * thousands * thousands;
            int sum = onesCube + tensCube + hundredsCube + thousandsCube;
            System.out.println(sum);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(9条)

报告相同问题?

问题事件

  • 系统已结题 10月9日
  • 已采纳回答 10月1日
  • 赞助了问题酬金15元 10月1日
  • 创建了问题 10月1日