java题库―编程题 河工大

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

diyi道编程题库:1、编写程序,计算下列分段函数的值。x(x=0)y=-x(x0)importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{floatx,y;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(请输入x:);Stringtemp=input.readLine();x=Float.parseFloat(temp);if(x=0){y=x;}else{y=-x;}System.out.println(y=+y);}}2、根据年龄,判断某人是否为成年。importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{intx;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(请输入x:);Stringtemp=input.readLine();x=Float.parseFloat(temp);if(x=18){System.out.println(成年人);}if(x18){System.out.println(未成年);}}}3、判断2020的奇偶性,并进行输出。publicclasstest{publicstaticvoidmain(String[]args){intx;x=2020;if(x%2==0)System.out.println(+x+是偶数);elseSystem.out.println(+x+不是偶数);}}4、比较两个数的大小,找出其中的最大数并输出。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{floatx,y,m;m=0;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(请输入x:);Stringtempx=inputx.readLine();x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(请输入y:);Stringtempy=inputy.readLine();y=Float.parseFloat(tempy);if(xy){m=x;}else{m=y;}System.out.println(最大数为+m);}}5、比较两个数的大小,找出其中的最小数并输出。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{floatx,y,m;m=0;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(请输入x:);Stringtempx=inputx.readLine();x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(请输入y:);Stringtempy=inputy.readLine();y=Float.parseFloat(tempy);if(xy){m=x;}else{m=y;}System.out.println(最小数为+m);}}6、编写一个Java程序,判断某年份是否为闰年。importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{floatx;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(请输入x:);Stringtemp=input.readLine();x=Float.parseFloat(temp);if(x%400==0){System.out.println(+x+是闰年);}elseif(x%4==0){System.out.println(+x+是闰年);}else{System.out.println(+x+不是闰年);}}}7、比较两个数的大小,找出其中的最大数和最小数并输出。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{floatx,y;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(请输入x:);Stringtempx=inputx.readLine();x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(请输入y:);Stringtempy=inputy.readLine();y=Float.parseFloat(tempy);if(xy){System.out.println(最小数为+x);System.out.println(最大数为+y);}else{System.out.println(最小数为+y);System.out.println(最大数为+x);}}}8、比较两个数的大小,找出其中的最大数和最小数,并输出最大数和最小数之差。importjava.io.*;publicclasska{publicstaticvoidmain(String[]args)throwsIOException{floatx,y,m;InputStreamReaderreaderx=newInputStreamReader(System.in);BufferedReaderinputx=newBufferedReader(readerx);System.out.println(请输入x:);Stringtempx=inputx.readLine();x=Float.parseFloat(tempx);InputStreamReaderreadery=newInputStreamReader(System.in);BufferedReaderinputy=newBufferedReader(readery);System.out.println(请输入y:);Stringtempy=inputy.readLine();y=Float.parseFloat(tempy);if(xy){System.out.println(最小数为+x);System.out.println(最大数为+y);m=y-x;System.out.println(最大数与最小数之差为+m);}else{System.out.println(最小数为+y);System.out.println(最大数为+x);m=x-y;System.out.println(最大数与最小数之差为+m);}}}9、编写程序,计算下列分段函数的值。x(x0)y=0(x=0)-x(x0)importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{floatx,y;y=0;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(请输入x:);Stringtemp=input.readLine();x=Float.parseFloat(temp);if(x0){y=x;}if(x==0){y=0;}if(x0){y=-x;}System.out.println(y=+y);}}10、编写程序,计算下列分段函数的值。x-1(x1)y=0(-1≤x≤1)x+10(x-1)importjava.io.*;publicclasstesta{publicstaticvoidmain(String[]args)throwsIOException{floatx,y;y=0;InputStreamReaderreader=newInputStreamReader(System.in);BufferedReaderinput=newBufferedReader(reader);System.out.println(请输入x:);Stringtemp=input.readLine();x=Float.parseFloat(temp);if(x1){y=x-1;}if(1.0=x&&x=-1.0){y=0;}if(x-1){y=x+10;}System.out.println(y=+y);}}第er道编程题库:1、编写一个Java程序在屏幕上输出“Hello!”。publicclasstest{publicstaticvoidmain(String[]args){System.out.println(Hello!);}}2、编写一个Java程序在屏幕上输出“Hello,world!”。publicclasstest{publicstaticvoidmain(String[]args){System.out.println(Hello,world);}}3、编写一个Java程序在屏幕上输出“Thisisjava!”。publicclasstest{publicstaticvoidmain(String[]args){System.out.println(Thisisjava!);}}4、编写一个Java程序在屏幕上输出“Thisismyprogram!”publicclasstest{publicstaticvoidmain(String[]args){System.out.println(Thisismyprogram!);}}5、编写一个Java

1 / 17
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功