三道很简单的题目。代码分别如下所示:
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
float a=sc.nextFloat();
int number=getCardsNumber(a);
if(number!=0){
System.out.println(number+" card(s)");
}
else{
break;
}
}
}
public static int getCardsNumber(float a){
int i=1;
float number=0;
while(number<a){
number+=1.0/(i+1);
i++;
}
i--;
return i;
}
}
import java.text.DecimalFormat;
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
float number=0;
int i=0;
for(i=0;i<12;i++){
float a=Float.valueOf(sc.nextLine()).floatValue();
number+=a;
}
DecimalFormat decimalFormat=new DecimalFormat(".00");
System.out.println("$"+ decimalFormat.format(number/12));
}
}
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int number=sc.nextInt();
for(int i=1;i<=number;i++){
double x=sc.nextDouble();
double y=sc.nextDouble();
double area=Math.PI*(x*x+y*y);
int year=0;
double sum=0;
while(sum<area){
sum+=100;
year++;
}
System.out.println("Property "+i+": This property will begin eroding in year "+year+".");
}
System.out.println("END OF OUTPUT.");
}
}
不解释了,没什么难的。