您好,欢迎访问三七文档
当前位置:首页 > 财经/贸易 > 资产评估/会计 > java简单测试习题
1¡¢Á·Ï°ÉϽڿÎÈý¸öʵÑ飺1£©ÊäÈëÈý¸öÊýÇóƽ¾ùÖµ£»2£©ÊäÈëÁ½¸öÊý½øÐл¥»»£»publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannersc=newScanner(System.in);inta=sc.nextInt();intb=sc.nextInt();intc=sc.nextInt();intaver=(a+b+c)/3;System.out.println(ƽ¾ùÊýΪ+aver);intf1=sc.nextInt();intf2=sc.nextInt();System.out.println(Á½¸öÊý·Ö±ðΪ+f1++f2);inttemp;temp=f1;f1=f2;f2=temp;System.out.println(Öû»ºó+f1++f2);}}2¡¢ÊäÈëÁ½¸öÊýÊä³ö×î´óµÄÊý£»publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannersc=newScanner(System.in);inta=sc.nextInt();intb=sc.nextInt();System.out.println(µÚÒ»¸öÊý£º+a);System.out.println(µÚ¶þ¸öÊý£º+b);if(ab)System.out.println(×î´óÊý+a);if(ba)System.out.println(×î´óÊý+b);elseSystem.out.println(Ò»Ñù´ó+a);}}3¡¢ÊäÈëÈý¸öÊýÊä³ö×î´óµÄ£»publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannersc=newScanner(System.in);inta=sc.nextInt();intb=sc.nextInt();intc=sc.nextInt();System.out.println(µÚÒ»¸öÊý£º+a);System.out.println(µÚ¶þ¸öÊý£º+b);System.out.println(µÚÈý¸öÊý£º+c);if(ab){if(bc)System.out.println(×î´óÊý+c);elseSystem.out.println(×î´óÊý+b);}else{if(ca)System.out.println(×î´óÊý+a);elseSystem.out.println(×î´óÊý+c);}}}4¡¢ÊäÈë·Ç0µÄÈýλÕûÊý£¬ÒÀ´ÎÊä³ö¸ÃÊýµÄ°ÙλÊý£¬Ê®Î»Êý£¬¸öλÊý£»publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannera=newScanner(System.in);intnum=a.nextInt();System.out.println(°Ùλ£º+num/100);System.out.println(ʮλ£º+num/10%10);System.out.println(¸öλ£º+num%10);}}5¡¢ÊäÈëÒ»¸ö°ë¾¶£¬Êä³öÔ²µÄÖܳ¤£¬Ô²µÄÃæ»ý£»publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannera=newScanner(System.in);floatr=a.nextFloat();System.out.println(Ô²Öܳ¤+2*3.14*r+Ô²Ãæ»ý+3.14*r*r);}}6¡¢ÊäÈëÒ»¸öÓ¢ÎÄ×Ö·û£¬ÊÇ×ÖĸÔòÊäÈëYES!·ñÔòÊä³öNO!,publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannersc=newScanner(System.in);charf=sc.next().charAt(0);if((f-'a'=0)&&('z'-f=0))System.out.println(YES);elseSystem.out.println(NO);}}7¡¢ÊäÈëÒ»¸öÊý×Ö1,2,3,4,5·Ö±ð´ú±íѧÉú³É¼¨:ÓÅÐ㣬Á¼ºÃ£¬Ò»°ã£¬¼°¸ñ£¬²»¼°¸ñ£»publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannersc=newScanner(System.in);inta=sc.nextInt();switch(a){case1:System.out.println(ÓÅÐã);break;case2:System.out.println(Á¼ºÃ);break;case3:System.out.println(Ò»°ã);break;case4:System.out.println(¼°¸ñ);break;case5:System.out.println(²»¼°¸ñ);break;default:System.out.println(²»´æÔÚ);break;}}}8¡¢Ð¡²¼Ê²ÂòÁËÒ»¿ð¼¦µ°£¬Èç¹û»µµ°ÉÙÓÚ5¸ö£¬Ëû¾Í³Ôµô£¬·ñÔòËû¾ÍÈ¥ÍË»õpublicclasscesh{publicstaticvoidmain(String[]args){intcount=0;int[]a=newint[40];for(inti=0;ia.length;i++){a[i]=(int)(Math.random()*100);if(a[i]=5||a[i]=95)count++;}System.out.println(»µµ°Êý£º+count+¸ö);if(count5)System.out.println(³Ôµô);elseSystem.out.println(ÍË»õ);}}9¡¢ÒªÇóÓû§ÊäÈëÁ½¸öÊýa¡¢b£¬Èç¹ûaÄܱ»bÕû³ý»òa¼Ób´óÓÚ1000£¬ÔòÊä³öa£¬·ñÔòÊä³öb;packagecesh;importjava.util.Scanner;publicclasscesh{publicstaticvoidmain(Stringargs[]){Scannersc=newScanner(System.in);inta=sc.nextInt();Scannerd=newScanner(System.in);intb=sc.nextInt();if((a%b==0)||(a+b)1000)System.out.println(a+a);elseSystem.out.println(b+b);}}10¡¢1+2+3+...+100;publicclasscesh{publicstaticvoidmain(Stringargs[]){ints=0;for(inti=1;i101;i++)s+=i;System.out.println(s=+s);}}11¡¢1-1/2+1/3-1/4+...+1/99-1/100;publicclasscesh{publicstaticvoidmain(Stringargs[]){doubles=0.0;for(doublei=1;i101;i++)if(i%2==0)s=s-(1/i);elses=s+(1/i);System.out.println(s=+s);}}12¡¢1+2!+3!+4!+5!£»publicclasscesh{publicstaticvoidmain(Stringargs[]){ints=0,j=1;for(inti=1;i6;i++){j=j*i;s=s+j;}System.out.println(s=+s);}}em.out.println(s=+s);13¡¢ÌâÄ¿£º´òÓ¡³öËùÓеÄË®ÏÉ»¨Êý£¬ËùνˮÏÉ»¨ÊýÊÇÖ¸Ò»¸öÈýλÊý£¬Æä¸÷λÊý×ÖÁ¢·½ºÍµÈÓÚ¸ÃÊý±¾Éí¡£ÀýÈ磺153ÊÇÒ»¸öË®ÏÉ»¨Êý£¬ÒòΪ153=1µÄÈý´Î·½£«5µÄÈý´Î·½£«3µÄÈý´Î·½¡£publicclasscesh{publicstaticvoidmain(Stringargs[]){intb;for(inti=100;i1000;i++){b=(i/100)*(i/100)*(i/100)+(i/10%10)*(i/10%10)*(i/10%10)+(i%10)*(i%10)*(i%10);if(b==i)System.out.println(Ë®ÏÉ»¨Êý+i++i/100++i/10%10++i%10);}}}1.³ÌÐò·ÖÎö£ºÀûÓÃforÑ»·¿ØÖÆ100-999¸öÊý£¬Ã¿¸öÊý·Ö½â³ö¸öλ£¬Ê®Î»£¬°Ùλ¡£14¡¢ÌâÄ¿£º¹ÅµäÎÊÌ⣺ÓÐÒ»¶ÔÍÃ×Ó£¬´Ó³öÉúºóµÚ3¸öÔÂÆðÿ¸öÔ¶¼ÉúÒ»¶ÔÍÃ×Ó£¬Ð¡ÍÃ×Ó³¤µ½µÚÈý¸öÔºóÿ¸öÔÂÓÖÉúÒ»¶ÔÍÃ×Ó£¬¼ÙÈçÍÃ×Ó¶¼²»ËÀ£¬ÎÊÿ¸öÔµÄÍÃ×Ó×ÜÊýΪ¶àÉÙ£¿µ½20¸öÔ·ֱðÊä³ö×ÜÊý¼°¸öÔÂÊý£»publicclasscesh{publicstaticvoidmain(String[]args){intsum=1;intb=1;for(inti=1;i21;i++){intc=sum;if(i2){System.out.print(µÚ+i+¸öÔ£º);System.out.println(c);}else{sum=sum+b;System.out.print(µÚ+i+¸öÔ£º);System.out.println(c);b=c;}}}}1.³ÌÐò·ÖÎö£ºÍÃ×ӵĹæÂÉΪÊýÁÐ1,1,2,3,5,8,13,21....15¡¢ÌâÄ¿£ººï×Ó³ÔÌÒÎÊÌ⣺ºï×ÓµÚÒ»ÌìÕªÏÂÈô¸É¸öÌÒ×Ó£¬µ±¼´³ÔÁËÒ»°ë£¬»¹²»ñ«£¬ÓÖ¶à³ÔÁËÒ»¸öµÚ¶þÌìÔçÉÏÓÖ½«Ê£ÏµÄÌÒ×Ó³ÔµôÒ»°ë£¬ÓÖ¶à³ÔÁËÒ»¸ö¡£ÒÔºóÿÌìÔçÉ϶¼³ÔÁËÇ°Ò»ÌìʣϵÄÒ»°ëÁãÒ»¸ö¡£µ½µÚ10ÌìÔçÉÏÏëÔÙ³Ôʱ£¬¼ûֻʣÏÂÒ»¸öÌÒ×ÓÁË¡£ÇóµÚÒ»Ìì¹²ÕªÁ˶àÉÙ¡£publicclasscesh{publicstaticvoidmain(String[]args){intsum=1;for(inti=0;i9;i++)sum=(sum+1)*2;System.out.println(µÚÒ»ÌìÕªÁË+sum+¸öÌÒ×Ó);}}16¡¢ÌâÄ¿£ºÓÐÒ»·ÖÊýÐòÁУº2/1£¬3/2£¬5/3£¬8/5£¬13/8£¬21/13...Çó³öÕâ¸öÊýÁеÄÇ°20ÏîÖ®ºÍ¡£publicclasscesh{publicstaticvoidmain(String[]args){doublesum=0;doublea=2.0,b=1.0;for(inti=0;i20;i++){sum=sum+a/b;doublec=a;a=a+b;b=c;}System.out.println(sum);}}17¡¢99³Ë·¨±í1*1=12*1=22*2=43*1=33*2=63*3=94*1=44*2=84*3=124*4=165*1
本文标题:java简单测试习题
链接地址:https://www.777doc.com/doc-4294397 .html