关于Java编程问题!一、 如果一个整数的各位数之和能被9整除,则这个数也能被9整除.编程判断一个整数N是否能被9整除.

1个回答

  • 以下是题1的代码

    public class Test {

    public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    int input = scanner.nextInt();

    boolean flag = false;

    int temp = 0;

    while(input%10>0){

    temp += input%10;

    input = input/10;

    }

    temp = temp + input;

    if(temp%9==0){

    flag = true;

    }

    System.out.println(flag?"能整除":"不能整除");

    }

    }

    以下是题2的代码

    public class Test1 {

    public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    System.out.println("请输入路程");

    int km = scanner.nextInt();

    double price = new Test1().getprice(km);

    System.out.println("单价/吨:"+price);

    System.out.println("请输入重量(T)");

    int h = scanner.nextInt();

    System.out.println("价格为:"+(price*h));

    }

    public double getprice(int km){

    double price = 0;

    if(km=100&&km=300&&km=500&&km