小白求教各位大神,关于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


POPMUISE
浏览 436回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java