浙大java练习题答案.docx
《浙大java练习题答案.docx》由会员分享,可在线阅读,更多相关《浙大java练习题答案.docx(18页珍藏版)》请在冰豆网上搜索。
浙大java练习题答案
40001
importjava.util.Scanner;
publicclassTest40001{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,n;
floatsum;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
System.out.println((int)(sum*1000+0.5)/1000.);
}
}
}
40002
importjava.util.Scanner;
publicclassTest40002{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,n;
doublefact;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
System.out.println(fact);
}
}
}
40003
importjava.util.Scanner;
publicclassTest40003{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,n;
doublex,mypow;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
x=in.nextDouble();
n=in.nextInt();
/*--------------------*/
System.out.println(mypow);
}
}
}
40004
importjava.util.Scanner;
publicclassTest40004{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,n,flag;
floatsum;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
System.out.println((long)(sum*10000+0.5)/10000.);
}
}
}
40005
importjava.util.Scanner;
publicclassTest40005{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,n,temp;
floatsum;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
sum=0;
for(i=1;i<=n;i++){
sum=(float)(sum+1.0/(2*i-1));
}
System.out.println(sum);
}
}
}
40006
importjava.util.Scanner;
publicclassTest40006{
publicstaticvoidmain(String[]args){
intri,repeat;
inttemp,flag;
doubleeps,item,sum;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
eps=in.nextDouble();
/*--------------------*/
System.out.println((int)(sum*10000+0.5)/10000.);
}
}
}
40007
importjava.util.Scanner;
publicclassTest40007{
publicstaticvoidmain(String[]args){
intri,repeat;
intbegin,c,end,f;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
begin=in.nextInt();
end=in.nextInt();
System.out.println("CelsiusFahrenheit");
/*--------------------*/
System.out.println(c+""+f);
}
}
}
}
40008
importjava.util.Scanner;
publicclassTest40008{
publicstaticvoidmain(String[]args){
intri,repeat;
intx,sum;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
x=in.nextInt();
/*--------------------*/
}
System.out.println(sum);
}
}
}
40009
importjava.util.Scanner;
publicclassTest40009{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,max,n,x;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
}
System.out.println(max);
}
}
}
40010
importjava.util.Scanner;
publicclassTest40010{
publicstaticvoidmain(String[]args){
intri,repeat;
intnumber,sum,n,r;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
System.out.println("number="+number+",sum="+sum);
}
}
}
40011
importjava.util.Scanner;
publicclassTest40011{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,n;
floata,b,s,t;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
System.out.println((int)(s*10000+.5)/10000.);
}
}
}
40012
importjava.util.Scanner;
publicclassTest40012{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
inti,n,a,sn,tn;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
a=in.nextInt();
n=in.nextInt();
/*--------------------*/
System.out.println(sn);
}
}
}
40013
importjava.util.Scanner;
publicclassTest40013{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
inti,m,n;
booleanflag=true;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
m=in.nextInt();
/*--------------------*/
}
if(flag)System.out.println("YES");
elseSystem.out.println("NO");
}
}
}
40014
importjava.util.*;
publicclassTest40014{
publicstaticvoidmain(String[]args){
Scannerin=newScanner(System.in);
intgcd,lcm,m,n,r;
intrepeat,ri;
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
m=in.nextInt();
n=in.nextInt();
if(m<=0||n<=0)
System.out.println("m<=0orn<=0");
else{
/*---------*/
System.out.println("theleastcommonmultiple:
"+lcm+",thegreatestcommondivisor:
"+gcd);
}
}
}
}
40021
importjava.util.Scanner;
publicclassTest40021{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
inti,n;
floats,t;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*--------------------*/
System.out.println((int)(s*10000+0.5)/10000.);
}
}
}
40022
importjava.util.Scanner;
publicclassTest40022{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
inti,digit,m,n,number,sum;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
m=in.nextInt();
n=in.nextInt();
/*------------------*/
}
}
}
40023
importjava.util.Scanner;
publicclassTest40023{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
intcount,i,j,k,m,n,sum;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
m=in.nextInt();
n=in.nextInt();
/*---------------------*/
System.out.println("count="+count+",sum="+sum);
}
}
}
40031
importjava.util.Scanner;
publicclassTest40031{
publicstaticvoidmain(String[]args){
intri,repeat,count,word,i;
Stringline;
charc;
Scannerin=newScanner(System.in);
repeat=(in.nextLine()).charAt(0)-'0';//输入repeat
for(ri=1;ri<=repeat;ri++){
line=in.nextLine();//输入一行字符
/*---------*/
System.out.println(count);
}
}
}
40032
importjava.util.Scanner;
publicclassTest40032{
publicstaticvoidmain(String[]args){
intri,repeat;
intdigit;
longn,temp,pow;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextLong();
/*---------*/
System.out.println();
}
}
}
40033
importjava.util.Scanner;
publicclassTest40033{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
intop1,op2,res;
charoperator;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
op1=in.nextInt();
operator=(in.next()).charAt(0);
/*---------*/
System.out.println(res);
}
}
}
40034
importjava.util.Scanner;
publicclassTest40034{
publicstaticvoidmain(String[]args){
intyear,m,n,repeat,ri;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
m=in.nextInt();
n=in.nextInt();
/*---------*/
}
}
}
40035
importjava.util.Scanner;
publicclassTest40035{
publicstaticvoidmain(String[]args){
intm,n,repeat,ri;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
m=in.nextInt();
/*---------*/
}
}
}
40036
importjava.util.Scanner;
publicclassTest40036{
publicstaticvoidmain(String[]args){
intdays,repeat,ri;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
}
}
}
40037
importjava.util.Scanner;
publicclassTest40037{
publicstaticvoidmain(String[]args){
inta,n,ri,count,number;
doublesum,ave;
Scannerin=newScanner(System.in);
n=in.nextInt();
for(ri=1;ri<=n;ri++){
/。
。
。
。
。
。
。
。
。
。
/
System.out.println("average="+Math.round(ave*100)/100.);
System.out.println("count="+count);
}
}
}
50001
importjava.util.Scanner;
publicclassTest50001{
publicstaticvoidmain(String[]args){
intri,repeat;
inti,n;
doubles;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*-----------*/
System.out.println((long)(s*10000+0.5)/10000.);
}
}
/*---------------*/
}
50002
importjava.util.Scanner;
publicclassTest50002{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
inti,n,a;
longsn;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
a=in.nextInt();
n=in.nextInt();
/*------------*/
System.out.println(sn);
}
}
/*------------*/
}
50003
importjava.util.Scanner;
publicclassTest50003{
publicstaticvoidmain(Stringargs[]){
intri,repeat;
intcount;
longn;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*---------*/
}
}
/*------------*/
}
50004
importjava.util.Scanner;
publicclassTest50004{
publicstaticvoidmain(Stringargs[]){
intri,repeat,n;
booleanflag;
Scannerin=newScanner(System.in);
repeat=in.nextInt();
for(ri=1;ri<=repeat;ri++){
n=in.nextInt();
/*---------*/
if(flag)System.out.println("YES");
elseSystem.out.println("NO");
}
}
/*------------*/
}