欢迎来到天天文库
浏览记录
ID:55719620
大小:603.00 KB
页数:49页
时间:2020-05-26
《蓝桥杯经典例题(Java语言实现).doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1.Fibonacci数列·importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannersca=newScanner(System.in);inti=sca.nextInt();int[]s=newint[i+1];s[1]=s[2]=1;for(intj=3;j<=i;j++){s[j]=(s[j-1]+s[j-2])%10007;}Sys
2、tem.out.println(s[i]);}}1.圆的面积 importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[]args){Scannersca=newScanner(System.in);intr=sca.nextInt();doublePI=Math.PI;doubleS=PI*r*r;Stringresult=String.format("%.7f",S);//四舍五入System.out.println(re
3、sult);result=String.format("%.8f",S).substring(0,(S+"").indexOf(".")+8);//不进行四舍五入,现取9位小数,再截取8位System.out.println(result);}}3.序列求和importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannersca=newScanne
4、r(System.in);longn=sca.nextInt();longresult=(1+n)*n/2;System.out.println(result);}}递归实现:importjava.util.Scanner;publicclassMain{staticintsum=0;publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannersca=newScanner(System.in);intn=sca.next
5、Int();System.out.println(f(n));}privatestaticintf(intn){//TODOAuto-generatedmethodstubif(n==1)return1;returnn+f(n-1);}}4.闰年判断当以下情况之一满足时,这一年是闰年:1.年份是4的倍数而不是100的倍数;2.年份是400的倍数。其他的年份都不是闰年。样例输入2013样例输出no样例输入2016样例输出yes数据规模与约定1990<=y<=2050。importjava.util.Sca
6、nner;publicclassMain{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubScannersc=newScanner(System.in);intyear=sc.nextInt();if(year%4==0&&year%100!=0)System.out.println("yes");elseif(year%400==0)System.out.println("yes");elseSystem.out.pri
7、ntln("no");}}5.01字串importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubfor(inti=0;i<2;i++){for(intj=0;j<2;j++){for(intk=0;k<2;k++){for(intl=0;l<2;l++){for(intm=0;m<2;m++){StringBufferstr=newStringBuffe
8、r();System.out.println(str.append(i).append(j).append(k).append(l).append(m));}}}}}}}6.字母图形importjava.util.Scanner;publicclassMain{publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intn=sc.nextInt();intm=s
此文档下载收益归作者所有