java程序设计报告答案

编程入门 行业动态 更新时间:2024-10-28 18:33:35

java<a href=https://www.elefans.com/category/jswz/34/1771020.html style=程序设计报告答案"/>

java程序设计报告答案

《Java语言程序设计实验报告》由会员分享,可在线阅读,更多相关《Java语言程序设计实验报告(25页珍藏版)》请在人人文库网上搜索。

1、本科实验报告课程名称: Java语言程序设计 实验地点: 致远楼 专业班级: 软工1507班 学号:2015005682学生姓名: 李俊慧 指导教师: 李君婵 实验名称实验一 Java语言基础实验目的1通过实验,掌握Java语言程序设计的基本方法。2学会Java语言中标示符的命名、运算符和表达式的应用。3熟练地掌握Java程序流程控制语句的应用。实验内容1. 编写应用程序,计算100(含100)以内所有偶数的和。2. 编写一个程序,求1-100间的素数。3. 使用for循环语句,编写程序输出以下图案。实验记录1. public class Javashiyan1_1 public static。

2、 void main(String args) int sum=0,i;for(i=1;inumm1+1) temp=numm1+1;numm1+1=numm1;numm1=temp;for(n=0;nb?ac?a:c:bc?b:c;min = ac?bc?c:b:ab?b:a;System.out.println(Max: +max+ Min: +min);public static void main(String args) Javashiyan3_3 A = new Javashiyan3_3();Javashiyan3_3 B = new Javashiyan3_3();Javash。

3、iyan3_3 C = new Javashiyan3_3();Javashiyan3_3 D = new Javashiyan3_3();Javashiyan3_3 E = new Javashiyan3_3();Javashiyan3_3 F = new Javashiyan3_3();A.Compare(12,23,34);B.Compare(40,23,94);C.Compare(12,83,34);D.Compare(42,73,34); E.Compare(99,67,8);F.Compare(99,2,40);4. public class Javashiyan3_4 publi。

4、c static void main(String args) Goods A = new Goods(Dong_Bei_ Rice,12.0,Heilongjiang);Goods B = new Goods(Te_lun_su_milk,63,China);System.out.println(-A.ShowMe()-);A.ShowMe();/ 显示A商品的名称价格产地System.out.println(-A.Add(20)-);A.Add(20);/ 上架20份A.ShowMe();System.out.println(-A.Sale(10)-);A.Sale(10);/ 销售10份。

5、A.ShowMe();System.out.println(-A.check()-);A.check();System.out.println(-A.query()-);A.query();B.ShowMe();B.Add(50); B.query();B.Sale(50);B.query();class Suppermarket String Merchandise = new String100;public void check() /*int t1;for(t1=0;Merchandiset1!=null;t1+) System.out.print(Name:+Merchandiset。

6、1);System.out.print( Inventory:+P.Inventory); */public void query() /*P.ShowMe();System.out.print( Inventory:+P.Inventory); */ class Goods extends Suppermarket String Name;double Price;String Producer;int Inventory,t=0;/ 表示货架上的数量public Goods() public Goods(String Name, double Price, String Producer)。

7、 this.Name = Name;this.Price = Price;this.Producer = Producer;Merchandiset = Name;t+; public void Sale(int y) / y 表示卖了几份Inventory -= y;if(Inventory = 0) Inventory = 0;System.out.println(OUT OF STOCK!);public void Add(int x) / x 表示上架的数量Inventory += x;public void ShowMe() System.out.println(Name:+Name。

8、+ Price:+Price+ Producer:+Producer+ Inventory:+Inventory);public void check() int t2;for(t2=0;t2100;t2+) if(Merchandiset2!=null) System.out.print(Name:+Merchandiset2);System.out.print( Inventory:+Inventory);System.out.println();public void query() ShowMe();/System.out.print( Inventory:+Inventory);实验。

9、结果1.2.3.4.实验名称实验四 多线程编程实验目的1 现成的概念、线程的生命周期。2 多线程的编程:扩展Thread类与使用Runnable接口。3 使用多线程机制实现动画实验内容1.创建简单的程序ThreeThread.java,该程序将创建三个线程,每个线程应当显示它所运行的时间(可以考虑使用Date类或Calendar类)。实验记录1. import java.util.*;public class Javashiyan5_3 extends Thread int pauseTime;String name;long s1,s2;public Javashiyan5_3(int x,。

10、 String n) pauseTime = x;name = n;public void run() while(true) try s1 = System.currentTimeMillis();System.out.println( *START* +name+:+new Date(System.currentTimeMillis();System.out.println(name+:+s1);Thread.sleep(pauseTime);s2 = System.currentTimeMillis();System.out.println( *END* +name+:+new Date。

11、(System.currentTimeMillis();System.out.println(| +name+ |+ has run:+(s2-s1);catch (Exception e) System.out.println(e);public static void main(String args) Javashiyan5_3 tp1 = new Javashiyan5_3(4000,Fast);tp1.start();Javashiyan5_3 tp2 = new Javashiyan5_3(5000,Middle);tp2.start();Javashiyan5_3 tp3 = n。

12、ew Javashiyan5_3(6000,Slow);tp3.start();实验结果1.实验名称实验五 图形用户界面编程实验目的1掌握文本组件、按钮和单、复选按钮组件的使用;掌握列表的使用,鼠标、键盘事件的处理;掌握布局控制的方法。实验内容1. 编写一个程序响应鼠标事件,当鼠标事件发生时,在状态条显示相应的时间信息。提示:使用showStatus(字符串)方法。2. 试设计一窗口,内含一个按钮。开始运行时,按钮显示“Click Me”字样,当按钮按下时,按钮显示为“Click Me Again”字样,再按一次,则按钮显示“Click Me”字样,依次循环。实验记录1. import jav。

13、ax.swing.*;import java.awt.event.*;import java.util.Date;import java.text.SimpleDateFormat;public class Javashiyan6_1 public static void main(String args) JFrame frm = new JFrame(#MouseEvent#);frm.setLayout(null);JLabel label1 = new JLabel(mouseEntered);label1.setBounds(15,5,200,25);JLabel label2 = 。

14、new JLabel(will show date);label2.setBounds(15,30,200,25);JTextField text = new JTextField(30);text.setBounds(15,55,200,30);frm.add(text);frm.add(label1);frm.add(label2); mymoulis hh = new mymoulis(text);frm.addMouseListener(hh);frm.setBounds(500,250,250,150);frm.setVisible(true);class mymoulis impl。

15、ements MouseListener JTextField text;JFrame frm;public mymoulis(JTextField text) this.text = text;public void mousePressed(MouseEvent e) public void mouseReleased(MouseEvent e) public void mouseClicked(MouseEvent e) public void mouseEntered(MouseEvent e) String s=2016-12-30 17:04:00;/(JTextField)e.g。

16、etSource).showStatus(s);SimpleDateFormat df = new SimpleDateFormat(yyyy-MM-dd HH:mm:ss);text.setText(df.format(new Date();frm.setTitle(df.format(new Date();public void mouseExited(MouseEvent e) String s=Please move the cur into textfield;text.setText(s);/(JTextField)e.getSource).showStatus(s);2. imp。

17、ort java.awt.BorderLayout;import java.awt.event.*;import javax.swing.*;public class Javashiyan6_2 public static void main(String args) JFrame frm = new JFrame(Javashiyan6_2);frm.setLayout(null);JButton btn = new JButton();btn.setText(Click Me);btn.setBounds(50,100,220,30); / x,y,width,heightfrm.add(。

18、btn);actionevent myevent = new actionevent(btn);btn.addActionListener(myevent);frm.setVisible(true);class actionevent implements ActionListener JButton btn;public actionevent(JButton btn) this.btn = btn;public void actionPerformed(ActionEvent e) String s1=Click Me;String s2=Click Me Again;String s=(。

19、JButton)(e.getSource().getText();/(JButton)e.getSource().setText(s);if(s=s1) btn.setText(s2);if(s=s2) btn.setText(s1);实验结果1.2.实验名称实验六 输入与输出实验目的1 掌握Java两种基本输入/输出流类的使用。2 掌握Java文件类型的使用。3 掌握文件的输入、输出方法。实验内容1. 编写程序,实现从键盘输入字符串并在屏幕上输出。2. 利用Java文件类File的方法,获取磁盘文件的文件名、长度、大小等特性。3. 编写程序,利用Java字符流文件输入/输出类,实现将源程序复。

20、制到另一个文件中。4. 编写一个程序,比较两个文件的内容是否相同。5. 编写一个程序,求2200之间的素数,并将结果保存在文件prime.dat中。再从该文件中读取内容并在屏幕上显示出来。实验记录1. import java.util.Scanner;public class Javashiyan7_1 public static void main(String args) Scanner sc = new Scanner(System.in);/Scanner sc1 = new Scanner(abcd sdsdfjh.adasdoij,asdji wqeuv);while(sc.has。

21、Next() System.out.println(sc.next(); 2. import java.io.File;public class Javashiyan7_2 public static void main(String args) File file = new File(/etc/default/grub);System.out.println(FileName:+file.getName();System.out.println(Length(Size):+file.length()+ Bytes);System.out.println(IsAbsolute:+file.i。

22、sAbsolute();System.out.println(LastModified:+file.lastModified();3. import java.io.*;public class Javashiyan7_3 public static void main(String args) FileWriter fw = null; / 写入文件FileReader fr = null;try fw = new FileWriter(./Javashiyan7_3_FileStream.txt);fr = new FileReader(/home/liberty/myJavachengx。

23、u/myJavashiyan/Javashiyan1/Javashiyan1_1/Makefile);/以下是读一个字符,写一个字符的方法/int ch=0;/while(ch=fr.read() != -1) /fw.write(ch);/ 以下是读一个数组大小,写一个数组大小的方法int t=0;char buf=new char1024;while(t=fr.read(buf)!=-1) fw.write(buf,0,t); catch(Exception e) System.out.println(e.toString();finally if(fr != null)try fr.cl。

24、ose();catch(Exception e2) throw new RuntimeException(fr-close-failed!);if(fw != null)try fw.close();catch(IOException e) throw new RuntimeException(fw-close-failed!);4. import java.io.*;public class Javashiyan7_4 public static void main(String args) throws IOException FileReader fr1;FileReader fr2;F。

25、ileReader fr3;FileReader fr4;fr1 = new FileReader(/home/liberty/myJavachengxu/myJavashiyan/Javashiyan7/Javashiyan7_4/111.txt);fr2 = new FileReader(/home/liberty/myJavachengxu/myJavashiyan/Javashiyan7/Javashiyan7_4/222.txt);fr3 = new FileReader(/home/liberty/myJavachengxu/myJavashiyan/Javashiyan7/Jav。

26、ashiyan7_4/333.txt);fr4 = new FileReader(/home/liberty/myJavachengxu/myJavashiyan/Javashiyan7/Javashiyan7_4/Makefile);int v1,v2,v3,v4;int f2=1,f3=1,f4=1;int i1=0,i2=0,i3=0,i4=0;int n1,n2,n3;int a1 = new int1000;int a2 = new int1000;int a3 = new int1000;int a4 = new int1000;/ a1while(v1=fr1.read()!=-。

27、1) a1i1=v1;i1+;/ a2while(v2=fr2.read()!=-1) a2i2=v2;i2+;/ a3while(v3=fr3.read()!=-1) a3i3=v3;i3+;/ a4while(v4=fr4.read()!=-1) a4i4=v4;i4+;/ a1 - a2for(n1=0;a1n1!=0|a2n1!=0;n1+) if(a1n1!=a2n1) f2=0;if(f2=1) System.out.println(1 is same to 2);else System.out.println(1 != 2);/ a1 - a3for(n2=0;a1n2!=0|a。

28、3n2!=0;n2+) if(a1n2!=a3n2) f3=0;if(f3=1) System.out.println(1 is same to 3);else System.out.println(1 != 3);/ a1 - a4for(n3=0;a1n3!=0|a4n3!=0;n3+) if(a1n3!=a4n3) f4=0;if(f4=1) System.out.println(1 is same to 4);else System.out.println(1 != 4);5. import java.io.*;public class Javashiyan7_5 public sta。

29、tic void main(String args) throws IOException int i,m,mark=1;int n=0,t=0,q=0,j;FileWriter fw;FileReader fr;fw = new FileWriter(/home/liberty/myJavachengxu/myJavashiyan/Javashiyan7/Javashiyan7_5/Javashiyan7_5_sushu.txt);int A = new int200;for(i=2;i=200;i+) mark=1;for(m=2;m=i-1;m+) if(i%m=0) mark=0;if。

30、(mark=1) An=i;n+;for(j=0;j200&Aj!=0;j+)fw.write(Aj);fw.close();fr = new FileReader(/home/liberty/myJavachengxu/myJavashiyan/Javashiyan7/Javashiyan7_5/Javashiyan7_5_sushu.txt);int value;while(value=fr.read()!=-1) System.out.print(value+t);q+;if(q%5=0)System.out.println();fr.close();System.out.println();System.out.println(However,the txt file cannot be viewed by VIM!);实验结果1.2.3.4.5.25欢迎下载。

更多推荐

java程序设计报告答案

本文发布于:2024-02-17 07:36:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1693205.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序设计   答案   报告   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!