JAVA实验报告_第1页
JAVA实验报告_第2页
JAVA实验报告_第3页
JAVA实验报告_第4页
JAVA实验报告_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

日期: 2018年5月 地点:明向校区公共机房6(1)实验题目,实验原理和内容1、 实验目的:JAVA结构化程序设计2、 实验原理:声明不同数据类型的变量,使用关系运算符和逻辑运算符,使用表达式语句与复合语句,使用选择语句,使用循环语句。实验内容及要求:1、题目1:编写程序,实现从键盘输入一个0到100之内的整数,把百分制分数到等级分数的转换 /=90 A/ 8089 B/ 7079 C/ 6069 D/ 60 E 2、成法口诀阵形3、华氏和摄氏的转换法4、.从键盘输入10个数,排序输出。要求:请同学们把调试好的程序及运行结果、存在的问题写在下面(不够可以附页)。1、package test1;import java.util.*; public class TEST1 public static void main(String args)System.out.println(请输入一个0到100之间的整数);Scanner scanner=new Scanner(System.in);int x;int m=scanner.nextInt();x=m/10; switch(x) case 9: System.out.println(A);break;case 8: System.out.println(B);break;case 7: System.out.println(C);break;case 6: System.out.println(D);break;default: System.out.println(E);break; 2、package test2;public class TEST2 public static void main(String args)int num;int m;for(int i=1;i=9;i+) for(int j=1;j=i;j+) num=i*j; System.out.print(j+*+i+=+num+ t); if(i=j) System.out.println(); 3、package test3;import java.util.*; public class TEST3 public static void main(String args)Scanner scanner=new Scanner(System.in);while(true) System.out.println(请输入要转换的温度类型:c或f);String a=scanner.nextLine();String num1=new String(c);String num2=new String(f);String num3=new String(exit);if(a.equals(num1) System.out.println(请输入要转换摄氏的温度:.); double C=scanner.nextFloat();System.out.println(对应的华氏温度为:);System.out.println(32+C*1.8+F);if(a.equals(num2) System.out.println(请输入要转换华氏的温度:.);double F=scanner.nextFloat();System.out.println(对应的摄氏温度为:+C);System.out.println(F-32)/1.8+C); if(a.equals(num3) break;String bank=scanner.nextLine();4、package test4;import java.util.*; public class Test4 public static void main(String args)Scanner scanner=new Scanner(System.in);int m;int a=new int10;for(int i=0;i=9;i+)ai=scanner.nextInt();int temp;for(int i=0;i10;i+)for(int j=i+1;jaj)temp=ai;ai=aj;aj=temp;for(int x=0;x=9;x+)System.out.print(ax+ );日期: 2018年5月 地点:明向校区公共机房6(2)实验题目,实验原理和内容一实验目的:数组、字符串与异常处理二实验原理:使用数组,使用字符串与字符串类,处理异常。三实验内容及要求:1. 编写一程序,计算矩阵A=7,9,4,5,6,8与矩阵B=9,5,2,8,5,9,7,2相乘,把结果存入矩阵C,并在屏幕输出结果。2. 使用冒泡排序(数组,数字为:63,4,24,1,3,5)3. 编写程序,测试字符串“你好,欢迎来到Java世界”的长度,将字符串的长度转换成字符串进行输出,并对其中的“Java”四个字母进行截取,输出截取字母以及它在字符串中的位置。要求:请同学们把调试好的程序及运行结果、存在的问题写在下面(不够可以附页)。1、package test;public class Test1 public static void main(String args)int A=7,9,4, 5,6,8;int B=9,5,2,8, 5,9,7,2, 3,6,2,9;int C=new int24;int x,i,j;for(i=0;i=1;i+)for(j=0;j=3;j+)int temp=0;for(x=0;x=2;x+)temp=Aix*Bxj+temp;Cij=temp;for(int m=0;m=1;m+)for(int n=0;n=3;n+)System.out.print(Cmn+t);System.out.println();2、package test;public class Test2public static void main(String args)int A=63,4,24,1,3,5;int x;for(int i=0;i=5;i+)for(int j=0;jAj)x=Ai;Ai=Aj;Aj=x; for(int i=0;i=5;i+)System.out.print(Ai+ );3、package test;public class Test3 public static void main(String args)String s=new String(你好,欢迎来到Java世界);int a=s.length();System.out.println(字符段长度为:+a);System.out.println(s.substring(7, 11);System.out.println(J位置:+s.indexOf(J);System.out.println(a位置:+s.indexOf(a);System.out.println(v位置:+s.indexOf(v);System.out.println(a位置:+s.indexOf(a,(s.indexOf(a)+1);日期: 2018年5月 地点:明向校区公共机房6(3)实验题目,实验原理和内容一实验目的:文件与数据流二实验原理:使用标准输入输出流,使用字符输入输出流,使用随机文件类,文件的读写操作。三实验内容及要求:1. 输入8个整数的数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。2. 创建一个文本文件memo.txt,编写程序实现打开该文本文件,每次读取一行内容,将每行作为一个字符串读入,并将字符串输出显示到屏幕上。要求:请同学们把调试好的程序及运行结果、存在的问题写在下面(不够可以附页)。1、package t1;import java.util.Scanner;public class T1 public static void main(String args) int a = new int8;Scanner scanner = new Scanner(System.in);System.out.println(请输入八个整数:);a0 = scanner.nextInt();int max=0,min=0;for(int i = 1; i = ai ? max:i;int temp;temp = a0;a0 = amax;amax = temp;for(int i = 1; i a.length; i+)min = amin = ai ? min:i;temp = a7;a7 = amin;amin = temp;for (int i = 0; i a.length; i+)System.out.print(ai + );scanner.close();2、package t1;import java.io.*;public class T1 public static void main(String args) throws IOExceptionFileReader fin=new FileReader(.memo.txt);BufferedReader bin=new BufferedReader(fin);String str;while(str=bin.readLine()!=null)System.out.println(str);bin.close();日期: 2018年5月 地点:明向校区公共机房6(4)实验题目,实验原理和内容一实验目的:文件与数据流。二实验原理:使用标准输入输出流,使用字符输入输出流,使用随机文件类,文件的读写操作。三实验内容及要求:1.使用标准输入输出流2.使用字符输入输出流3.使用随机文件类4.文件的读写操作4 题目:1. 编写一个程序,在控制台中窗口中提示输入两个整数,然后接收这两个整数,并输出它们的和,下面是运行过程的示例:请输入第一个整数:45请输入第二个整数:23计算结果:45+23=682. 编写一个程序,要求输入5个学生的成绩(从0到100的整数),并将这5个数保存到文件“data.txt”中。然后再编写一个程序,从文件的“data.txt”中读取这5个学生的成绩,计算并输出它们的平均数,然后再按从小到大的顺序输出这5个学生的成绩。3. 编写一个程序。修改在上一题生成的文件“data.txt”中的文件内容,使得第三个学生的成绩变成为这5个学生的平均成绩,并在控制台窗口中输出在修改以后的文件内容。4. 输入一个不多于5位的正整数,要求:一,求它是几位数,二,逆序打印出各位数字。要求:请同学们把调试好的程序及运行结果、存在的问题写在下面(不够可以附页)。1、package TEST1;import java.util.Scanner;public class tese1 public static void main(String args)System.out.print(请输入第一个整数:);Scanner s1=new Scanner(System.in);int a1=s1.nextInt();System.out.print(请输入第二个整数:);Scanner s2=new Scanner(System.in);int a2=s2.nextInt();System.out.print(计算结果:+a1+a2+=+(a1+a2);2、package TEST2;import java.io.*;import java.util.*;public class test2 private File file=new File(data.txt);private FileOutputStream fos;private PrintWriter pw;public void writeScore()try fos=new FileOutputStream(file,false);pw=new PrintWriter(fos);Scanner input=new Scanner(System.in);for(int i=0;i5;i+)String score=input.nextLine();pw.println(score);pw.flush();fos.flush();pw.close();fos.close(); catch (FileNotFoundException e) e.printStackTrace(); catch (IOException e) e.printStackTrace();public int readScore()intsort=null;try int pos=0;BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream(file);String line=null;sort=new int5;while(line=br.readLine()!=null)sortpos=Integer.parseInt(line);pos+;br.close(); catch (FileNotFoundException e) e.printStackTrace(); catch (NumberFormatException e) e.printStackTrace(); catch (IOException e) e.printStackTrace();return sort;public static void main(Stringargs)test2 d=new test2();int sum=0;System.out.println(请输入成绩:);d.writeScore();int sort=d.readScore();Arrays.sort(sort);System.out.println(排序以后的成绩:);for(int i:sort)sum+=i;System.out.print(i+ );System.out.println();System.out.println(平均值:+sum/sort.length);3、package start;import java.io.BufferedReader;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class Xiugai public static void main(String args) throws IOException FileReader bout=new FileReader(F:eclipseeclipse20180305data.txt);BufferedReader fout1 =new BufferedReader(bout);String value;int i=0;String a = new String6;while(value=fout1.readLine()!=null) ai=value;i+;System.out.println(原来的成绩);for(int j=0; j5; j+) System.out.println(aj);a2=String.valueOf(Integer.parseInt(a0)+Integer.parseInt(a1)+Integer.parseInt(a2)+Integer.parseInt(a3)+Integer.parseInt(a4)/5);bout.close();FileOutputStream testfile = new FileOutputStream(F:eclipseeclipse20180305data.txt);testfile.close();testfile.write(new String().getBytes();FileWriter fout=new FileWriter(F:eclipseeclipse20180305data.txt,true);for(int i1=0; i15; i1+) fout.write(ai1+rn);System.out.println(修改后的成绩);for(int j=0; j99999)System.out.println(error); if(a9999) System.out.println(5位);int x=new int5; x0=a%10;x1=(a/10%10);x2=a/100%10;x3=a/1000%10;x4=a/10000; for(int i=0;i999&a10000) System.out.println(4位);int x=new int4; x0=a%10;x1=(a/10%10);x2=a/100%10;x3=a/1000; for(int i=0;i99&a1000) System.out.println(3位);int x=new int3; x0=a%10;x1=(a/10%10);x2=a/100; for(int i=0;i9&a100) System.out.println(2位);int x=new int2; x0=a%10;x1=a/10; for(int i=0;i0&a10) System.out.println(1位); System.out.print(a);日期: 2018年5月 地点:明向校区公共机房6(5)实验题目,实验原理和内容一实验目的:综合习题及多线程二实验原理:使用前面所学知识,综合编程三实验内容及要求:综合习题及多线程四题目1. 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单,有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。2. 打印出杨辉三角形(要求打印出10行如下图)3. 某个公司采用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下:每位数字都加上5,然后用和除以10的余数代替该数字,再将第一位和第四位交换,第二位和第三个交换。请用程序实现加密算法。要求:请同学们把调试好的程序及运行结果、存在的问题写在下面(不够可以附页)。1、package TEST2;public class test2public static void main(Stringargs) char i,j,k; for(i=x;i=z;i+) for(j=x;j=z;j+) if(i!=j) for(k=x;k=z;k+) if(i!=k & j!=k) if(i!=x & k!=x& k!=z) System.out.println( a Vs +i+; b Vs +j+; c Vs +k); 2、package TEST1;public class tese1 public static void main(String args) int length = 10; int arr = new intlength; for(int i = 0; i arr.length; i+) for(int m = 0; m arr.length - 1 - i; m+) System.out.print( ); arri = new inti+1; for(int j = 0; j arri.length; j+) if( j = 0 | j = arri.length -1 ) arrij = 1; else arrij = arri -1j - 1 + arri - 1j; System.out.printf(%4d,arrij); System.out.println(); 3、package TEST2;import java.util.*;public class test2 public static void main(String args) System.out.println(请输入数据:);int a=new int4;Scanner s=new Scanner(System.in);for(int i=0;i=3;i+) ai=s.nextInt();System.out.println(原数据:);for(int i=0;i=3;i+) System.out.print(ai);System.out.println();for(int i=0;i=3;i+) ai=(ai+5)%10;int temp;temp=a3;a3=a0;a0=temp;temp=a1;a1=a2;a2=temp;System.out.println(加密后:);for(int i=0;i=3;i+) System.out.print(ai);日期: 2018年6月 地点:明向校区公共机房6(6)实验题目,实验原理和内容一实验目的:了解Java图形用户界面的常用组件(如窗口,按钮,文本框,选择框,滚动条等)的使用方法,了解如何java界面设计中的布局管理机制,以及如何使用java的事件处理机制实现界面的互动。二实验要求1.了解Java Swing 组件的使用方法。2. 学习使用布局管理器对组件进行管理的办法。3.理解java的事件处理机制,为不同的组件编写对应的事件处理程序。4.掌握编写独立运行的窗口界面的方法。三实验内容及要求1.在应用程序窗体中安排两个文本框分别用来输入两个整数,两个按钮分别为“+”、“*”,一个结果标签。点击按钮“+”将两文本框的数据做加法运算;点击按钮“*”做乘法运算,将结果显示在标签中。2.设计一个在windows系统中可以使用的“计算器”窗口并实现(+、,等)其功能。要求:请同学们把调试好的程序及运行结果、存在的问题写在下面(不够可以附页)。1:package start;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Jiajian extends JFrame implements ActionListener JLabel res;JTextField f1, f2;public Jiajian() super(动作事件例程);Container c=getContentPane();f1 = new JTextField(20);f2 = new JTextField(20);JButton b1 = new JButton(+);JButton b2 = new JButton(*);res = new JLabel( 运算结果 );c.setLayout(new GridLayout(3, 2);c.add(f1);c.add(f2);c.add(b1);c.add(b2);c.add(res);b1.addActionListener(this);b2.addActionListener(this);public void actionPerformed(ActionEvent e) int x1 = Integer.parseInt(f1.getText();int x2 = Integer.parseInt(f2.getText();if (e.getActionCommand() = (+)res.setText( + (x1 + x2);else res.setText( + (x1 * x2);public static void main(String args) Jiajian my =new Jiajian();my.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);my.setSize(300,200);my.setVisible(true);2:package start;import java.awt.BorderLayout;import java.awt.Color;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener; import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextField; public class Jisuanji extends JFrame implements ActionListener private final String KEYS = 7, 8, 9, /, sqrt, 4, 5, 6, *, %, 1, 2, 3, -, 1/x, 0, +/-, ., +, = ; private final String COMMAND = Backspace, CE, C ; private final String M = , MC, MR, MS, M+ ; private JButton keys = new JButtonKEYS.length; private JButton commands = new JButtonCOMMAND.length; private JButton m = new JButtonM.length; private JTextField resultText = new JTextField(0); private boolean firstDigit = true; private double resultNum = 0.0; private String operator = =; private boolean operateValidFlag = true; public Jisuanji() super(); init(); this.setBackground(Color.LIGHT_GRAY); this.setTitle(计算器); this.setLocation(500, 300); this.setResizable(false); this.pack(); private void init() resultText.setHorizontalAlignment(JTextField.RIGHT); resultText.setEditable(false); resultText.setBackground(Color.WHITE); JPanel calckeysPanel = new JPanel(); calckeysPanel.setLayout(new GridLayout(4, 5, 3, 3); for (int i = 0; i KEYS.length; i+) keysi = new JButton(KEYSi); calckeysPanel.add(keysi); keysi.setForeground(Color.blue); keys3.setForeground(Color.red); keys8.setForeground(Color.red); keys13.setForeground(Color.red); keys18.setForeground(Color.red); keys19.setForeground(Color.red); JPanel commandsPanel = new JPanel(); commandsPanel.setLayout(new GridLayout(1, 3, 3, 3); for (int i = 0; i COMMAND.length; i+) commandsi = new JButton(COMMANDi); commandsPanel.add(commandsi); commandsi.setForeground(Color.red); JPanel calmsPanel = new JPanel(); calmsPanel.setLayout(new GridLayout(5, 1, 3, 3); for (int i = 0; i M.length; i+) mi = new JButton(Mi); calmsPanel.add(mi); mi.setForeground(Color.red); JPanel panel1 = new JPanel();panel1.setLayout(new BorderLayout(3, 3); panel1.add(North, commandsPanel); panel1.add(Center, calckeysPanel); JPanel top = new JPanel(); top.setLayout(new BorderLayout(); top.add(Center, resultText); getContentPane().setLayout(new BorderLayout(3, 5); getContentPane().add(North, top); getContentPane().add(Ce

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论