java编程题目:编写一个程序,输入一个三位正整数,输出个、十、百位数字的立方和。新手,请详细一点

如题所述

import java.util.*;
public class YUGI{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);

System.out.println("输入一个三位数: ");

int abc = sc.nextInt();

sc.close();

int a = abc/100;

int b = abc / 10 % 10;

int c = abc % 10;

int x = Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3);

System.out.println("立方和:" +x);

}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2017-06-20
package BaseExec;

import java.util.Scanner;

public class PrintSum {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int baiwei = num/100;
int shiwei = (num - baiwei *100)/10;
int gewei = num%10;
System.out.println(baiwei + " " + shiwei + " " + gewei);
System.out.println(baiwei*baiwei*baiwei + shiwei*shiwei*shiwei + gewei*gewei*gewei);
}

}
相似回答