分别输入两个数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
相关分类