Elsa镇魂女孩 2019-02-21 02:25 采纳率: 62.5%
浏览 452
已采纳

小白求教各位大神,关于java,求余数

分别输入两个数double a,b;
    r = b - count * a ;  
    求count为几的时候,r=1.0;

    例如,double a = 1.3;
         double b = 3.9;
     那么,count = 3

import java.util.Scanner;

public class Exg {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);
        System.out.println("Pleat enter the first number!");
        double a = s.nextDouble();

        Scanner w = new Scanner(System.in);
        System.out.println("Pleat enter the second number (larger than the first number) !");
        double b = w.nextDouble();
        double count=1.0;
        double r;
        do { 
            r = b- count * a;
            count ++;
        }while(r==1.0);

        System.out.println(count);


    }   
}

结果大概的样子为:

Pleat enter the first number!
2.3
Pleat enter the second number (larger than the first number) !
36.9
2.0


好忧伤啊, 不论添什么数,结果都是2.0

  • 写回答

2条回答 默认 最新

  • Elsa镇魂女孩 2019-02-21 04:53
    关注

    import java.util.Scanner;

    public class Exg {

    public static void main(String[] args) {
    
        Scanner s = new Scanner(System.in);
        System.out.println("Pleat enter the first number!");
        double a = s.nextDouble();
    
        Scanner w = new Scanner(System.in);
        System.out.println("Pleat enter the second number (larger than the first number) !");
        double b = w.nextDouble();
    
        double d = (b-1.0)/a;
        int count = (int) d;
        System.out.println(count);
    
    
    }   
    

    }

    结果:
    Pleat enter the first number!

    2.1
    Pleat enter the second number (larger than the first number) !
    10.1
    4

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波