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条)

报告相同问题?

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格