解题代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
float c;
while ((c = stdin.nextFloat()) != 0.00) {
int num = getCards(c);
System.out.println(num + " card(s)");
}
}
private static int getCards(float c) {
int i = 2;
float sum = (float)1/i;
while (c > sum) {
sum += (float)1/(++i);
}
return i-1;
}
}
1.Java基本数据类型
数据类型 | 大小 | 范围 | 默认值 |
byte(字节) | 8 | -128 - 127 | 0 |
shot(短整型) | 16 | -32768 - 32768 | 0 |
int(整型) | 32 | -2147483648 - 2147483648 | 0 |
long(长整型) | 64 | -9233372036854477808 - 9233372036854477808 | 0 |
float(浮点型) | 32 | -3.40292347E+38 - 3.40292347E+38 | 0.0f |
double(双精度) | 64 | -1.79769313486231570E+308 - 1.79769313486231570E+308 | 0.0d |
char(字符型) | 16 | '\u0000 - u\ffff' | '\u0000' |
boolean(布尔型) | 1 | true/false | false |