一道初学者的Java题目,急求大大解题~

2025-01-02 23:32:41
推荐回答(5个)
回答1:

第二个的答案把加号改成-号就对了,59条
public class A4{

public static void main(String[] args) {
double fish = 0;
for (int i =11;i<11*5*4;i++)
{
fish=i;
for(double j=2;j<=5;j++)
{
fish=fish-(fish/j+1/j);
}
if((int)fish==11)
{
System.out.println(i);
break;
}
}

}
}

回答2:

答案 59
public class Fish {
public static void main(String[] args) {
for(int i=0; i<10000; i++) {
double remainder = sell(i);
if(Math.abs(remainder)<0.01) {
System.out.println("total fish "+i);
break;
}
}
}

static double sell(int total) {
double remainder = total;
for(int i=2; i<=5; i++) {
double sold = remainder*1.0/i + 1.0/i;
remainder -= sold;
}
remainder -= 11;
return remainder;
}
}

回答3:

public class A4 {

public static void main(String[] args) {
double fish = 0;

for (int i = 11; i < 11 * 5 * 4; i++) {
fish = i;
double one = fish - fish / 2 + (double) 1 / 2;
double two = one - one / 3 + (double) 1 / 3;
double three = two - two / 4 + (double) 1 / 4;
double four = three - three / 5 + (double) 1 / 5;

if((int)four==11){
System.out.println(fish);
break;
}
}

}
}

回答4:

public class Test()
{
public double countFish()
{
double total=11;
for(int i=4;i>0;i--)
{
total=(total+1/(i+1))*((i+1)/i);
}
return total;
}
public static void main(String[] args) {
System.out.println(new Test().countFisht());

}
}

回答5:

一个鱼贩子有1缸鱼分5次卖,第一次卖1缸鱼的二分之一加二分之一条;第二次卖余下的三分之一加三分之一条;第三次卖余下的四分之一加四分之一条;第四次卖余下的五分之一加五分之一条;最后卖出11条。求鱼缸里原来有多少条?