Java实用教程第二版常用语句

上传人:飞*** 文档编号:44437444 上传时间:2018-06-09 格式:DOC 页数:23 大小:144KB
返回 下载 相关 举报
Java实用教程第二版常用语句_第1页
第1页 / 共23页
Java实用教程第二版常用语句_第2页
第2页 / 共23页
Java实用教程第二版常用语句_第3页
第3页 / 共23页
Java实用教程第二版常用语句_第4页
第4页 / 共23页
Java实用教程第二版常用语句_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《Java实用教程第二版常用语句》由会员分享,可在线阅读,更多相关《Java实用教程第二版常用语句(23页珍藏版)》请在金锄头文库上搜索。

1、import java.applet.*; import java.awt.*; public class Boy extends Applet public void paint (Graphics g) g.setColor(Color.red);g.drawString(“我一边喝着咖啡,一边学 Java 呢“,5,30);g.setColor(Color.blue);g.drawString(“我学得很认真“,10,50); public class Ex3 public static void main (String args) long sum=1,temp=1;for (int

2、 i=2;ic?a:c; d=d2b?d:b; System.out.println(b); public class Hello public static void main (String args) System.out.println(“你好,很高兴学习 Java“); import java.lang.*; class Trangle double a,b,c,p;boolean s;Trangle(double a,double b,double c) this.a=a; this.b=b; this.c=c; public double 周长() return a+b+c; p

3、ublic double 求面积() p=(a+c+b)/2;return Math.sqrt(p*(p-a)*(p-b)*(p-c); void judgeTrangle() if (a+b)c elses=false; class Leder double ub,db,h;Leder(double ub,double db,double h)this.ub=ub; this.db=db; this.h=h;double 面积()return (ub+db)*h)/2; class Circle double r;double pi=3.1415926;Circle(double r)thi

4、s.r=r;double 求周长()return 2*r*pi;double area()return r*r*pi; public class Example public static void main (String args) Trangle sanjiao;Leder tixing; Circle yuan; sanjiao=new Trangle(3.0,4.0,5.0); System.out.println(“三角形的周长:“+sanjiao.周长(); System.out.println(“三角形的面积:“+sanjiao.求面积(); tixing=new Leder(

5、2.0,4.0,1.0); System.out.println(“梯形的面积:“+tixing.面积(); yuan=new Circle(3.0);System.out.println(“圆的周长:“+yuan.求周长(); System.out.println(“圆的面积:“+yuan.area(); class Company Employee employee;double salaries=0;Company(Employee employee)this.employee=employee;public double salariesPay()salaries=0;for (int

6、 i = 0; i =0)root1=(-b+Math.sqrt(disk)/(2*a);root2=(-b-Math.sqrt(disk)/(2*a);System.out.printf(“方程的根:%f,%fn“,root1,root2); elseSystem.out.printf(“方程没有实根n“);elseSystem.out.println(“不是一元 2 次方程“); public void setCoefficient(double a,double b,double c)this.a=a;this.b=b;this.c=c;if(a!=0)boo=true; else bo

7、o=false; import tom.jiafei.*; class SunRise public static void main(String args ) SquareEquation equation=new SquareEquation(4,5,1);equation.getRoots();equation.setCoefficient(-3,4,5);equation.getRoots(); public class EditString public static StringBuffer edit(String s)StringBuffer result=new String

8、Buffer();for(int i=0;i=a return result; public class Example public static void main(String args)String s=“student Z 12 name 56, java.“;System.out.println(EditString.edit(s); import java.util.Date; import java.text.SimpleDateFormat; class Example1 public static void main(String args)Date nowTime=new

9、 Date();SimpleDateFormat matter1=new SimpleDateFormat(“北京时间:E HH:mm:ss“);System.out.println(matter1.format(nowTime); import java.io.*; import java.util.*; public class Example2 public static void main(String args) throws IOException int year,month; String str; BufferedReader br=new BufferedReader(ne

10、w InputStreamReader(System.in); str=br.readLine(); year=Integer.parseInt(str); str=br.readLine(); month=Integer.parseInt(str); System.out.println(year+“年“+month+“月“);int allDay;if(year%4=0if(month=1|month=3|month=5|month=7|month=8|month=10|month=12)allDay=31;else allDay=30; else if(month=2)allDay=28

11、; else if(month=1|month=3|month=5|month=7|month=8|month=10|month=12)allDay=31;else allDay=30;System.out.println(“ 日 一 二 三 四 五 六“);Calendar 日历=Calendar.getInstance(); 日历.set(year,month-1,1); int 星期几=日历.get(Calendar.DAY_OF_WEEK)-1; String a=new String星期几+allDay; for(int i=0;i星期几;i+) ai=“*“; for(int i=

12、星期几,n=1;i星期几+allDay;i+) if(n=9) ai=String.valueOf(n)+“ “; else ai=String.valueOf(n) ; n+; for(int i=0;ia.length;i+) if(i%7=0) System.out.println(“); System.out.print(“ “+ai); import java.awt.*; import java.awt.event.*; import java.util.*; class WindowTextArea extends Frame implements TextListener Te

13、xtArea text1,text2; WindowTextArea(String s) super(s); setLayout(new FlowLayout(); text1=new TextArea(5,23); text2=new TextArea(5,23); add(text1); add(text2); text2.setEditable(false); text1.addTextListener(this); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.

14、exit(0); ); setBounds(100,100,400,160); setVisible(true); validate(); public void textValueChanged(TextEvent e) String s=text1.getText(); StringTokenizer geshu=new StringTokenizer(s); int n=geshu.countTokens(); double a=new doublen; for(int i=0;in;i+) String temp=geshu.nextToken(); double date=Doubl

15、e.parseDouble(temp); ai=date; double sum=0,average; for(int i=0;in;i+) sum=sum+ai; average=sum/n; text2.setText(null); text2.append(“和:“+sum+“n“+“平均数:“+average); public class Example public static void main(String args) WindowTextArea win=new WindowTextArea(“计算的窗口“); import java.awt.*; import java.awt.event.*; class WindowTextArea extends Frame implements ActionListener TextField text1,text2,text3; Button button1,butt

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号