欢迎来到天天文库
浏览记录
ID:43485228
大小:80.29 KB
页数:10页
时间:2019-10-07
《JAVA编程题 (2)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.编写一个具有交互功能的JavaApplication程序,提示从键盘输入应付金额和实付金额后,计算并输出找零或欠付金额。//编写一个具有交互功能的JavaApplication程序,提示从键盘输入应付金额amountpayable和实付金额Paidamount后,计算并输出找零change或欠付金额Owepaytheamount。importjava.util.Scanner;publicclasscount{publicstaticvoidmain(String[]args){intamountPayable,paidAmount,change,owePay;Scanneramount
2、=newScanner((System.in));//创建Scanner类的实例amountSystem.out.print("请输入应付金额:");amountPayable=amount.nextInt();//从键盘读入一个整数赋值给amountPayableSystem.out.print("请输入实付金额:");paidAmount=amount.nextInt();//从键盘读入一个整数赋值给paidAmountif(amountPayable3、hange);}if(amountPayable==paidAmount)System.out.print("既不找零也不欠付");if(amountPayable>paidAmount){owePay=amountPayable-paidAmount;System.out.print("欠付金额:"+owePay);}}}2.编写一个JavaApplet程序,使该程序运行后输出字符串“Don’tputofftilltomorrowwhatshouldbedonetoday.”。//编写一个JavaApplet程序,使该程序运行后输出字符串“Don’tputofftilltomorrowwh4、atshouldbedonetoday.”。importjava.applet.Applet;//引入java..applet包中Applet类importjava.awt.Graphics;//引入java.awt包中Graphics类publicclassadageextendsApplet{//继承Applet类publicvoidpaint(Graphicsg){g.drawString("Don’tputofftilltomorrowwhatshouldbedonetoday.",40,75);//在(40,75)坐标处绘制字符串"Don’tputofftilltomorrowwh5、atshouldbedonetoday."}}3.编写程序:将给定的一字符串倒序输出。//将给定的一字符串倒序输出。importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;publicclasscharDemo{publicstaticvoidmain(String[]args){BufferedReaderbr=null;Strings="";Strings1="";try{br=newBufferedReader(newInputStreamReader(System.i6、n));System.out.println("请输入字符并以回车结束:");//读入键盘输入s=br.readLine();StringBufferss=newStringBuffer(s);ss.reverse();//StringBuffer类的逆序函数s1=ss.toString();System.out.println("你输入的是:"+s);System.out.println("逆序以后是:"+s1);}catch(IOExceptione){e.printStackTrace();}catch(Exceptione){e.printStackTrace();}finally{7、try{br.close();}catch(Exceptione){e.printStackTrace();}}}4.编写一个字符界面的JavaApplication程序,接受用户输入的10个整数,并输出这10个整数之和。//编写一个字符界面的JavaApplication程序,接受用户输入的10个整数,并输出这10个整数之和。importjava.util.Scanner;publicclasssum{pu
3、hange);}if(amountPayable==paidAmount)System.out.print("既不找零也不欠付");if(amountPayable>paidAmount){owePay=amountPayable-paidAmount;System.out.print("欠付金额:"+owePay);}}}2.编写一个JavaApplet程序,使该程序运行后输出字符串“Don’tputofftilltomorrowwhatshouldbedonetoday.”。//编写一个JavaApplet程序,使该程序运行后输出字符串“Don’tputofftilltomorrowwh
4、atshouldbedonetoday.”。importjava.applet.Applet;//引入java..applet包中Applet类importjava.awt.Graphics;//引入java.awt包中Graphics类publicclassadageextendsApplet{//继承Applet类publicvoidpaint(Graphicsg){g.drawString("Don’tputofftilltomorrowwhatshouldbedonetoday.",40,75);//在(40,75)坐标处绘制字符串"Don’tputofftilltomorrowwh
5、atshouldbedonetoday."}}3.编写程序:将给定的一字符串倒序输出。//将给定的一字符串倒序输出。importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;publicclasscharDemo{publicstaticvoidmain(String[]args){BufferedReaderbr=null;Strings="";Strings1="";try{br=newBufferedReader(newInputStreamReader(System.i
6、n));System.out.println("请输入字符并以回车结束:");//读入键盘输入s=br.readLine();StringBufferss=newStringBuffer(s);ss.reverse();//StringBuffer类的逆序函数s1=ss.toString();System.out.println("你输入的是:"+s);System.out.println("逆序以后是:"+s1);}catch(IOExceptione){e.printStackTrace();}catch(Exceptione){e.printStackTrace();}finally{
7、try{br.close();}catch(Exceptione){e.printStackTrace();}}}4.编写一个字符界面的JavaApplication程序,接受用户输入的10个整数,并输出这10个整数之和。//编写一个字符界面的JavaApplication程序,接受用户输入的10个整数,并输出这10个整数之和。importjava.util.Scanner;publicclasssum{pu
此文档下载收益归作者所有