北京交通大学java语言程序设计实验报告

上传人:ji****72 文档编号:27019607 上传时间:2018-01-05 格式:DOCX 页数:28 大小:1.03MB
返回 下载 相关 举报
北京交通大学java语言程序设计实验报告_第1页
第1页 / 共28页
北京交通大学java语言程序设计实验报告_第2页
第2页 / 共28页
北京交通大学java语言程序设计实验报告_第3页
第3页 / 共28页
北京交通大学java语言程序设计实验报告_第4页
第4页 / 共28页
北京交通大学java语言程序设计实验报告_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《北京交通大学java语言程序设计实验报告》由会员分享,可在线阅读,更多相关《北京交通大学java语言程序设计实验报告(28页珍藏版)》请在金锄头文库上搜索。

1、1“Java 语言程序设计”实验报告实验 2刘黎(12271012) 电子信息工程学院 2014-10-13一、 实验要求二、 实验环境 实验地点:东校区机房 实验时间:2014 年 10 月 13 日 操作系统:Windows7 JDK 版本:三、 程序源代码public class Test2public static void main(String arg)char myName=刘,黎;int myID=12271012;System.out.printf(我的名字是:);System.out.print(myName);System.out.printf( 我的学号是:);Syst

2、em.out.println(myID);System.out.printf( );System.out.println(Integer.toHexString(myID);System.out.printf(我的名字的 Unicode 编码是:);System.out.println(Integer.toHexString(myName0)+ +Integer.toHexString(myName1);System.out.printf(名字的 unicode 码变换后是:);myName0 = 1;myName1 = 1;System.out.print(Integer.toHexStri

3、ng(myName0)+ +Integer.toHexString(myName1);System.out.printf(我的名字变成了:);System.out.println(myName);int a,b,c;a = myID/1000000;b = myID%1000000/1000;c = myID%1000;System.out.printf(我的学号的三个段分别是:);System.out.print(a+ +b+ +c);四、 程序运行结果2五、 问题和总结今天是第二次 java 实验上机。这个实验做的是 java 的输出指令语句练习,其中包括了字符串数组的使用,字符串的连接,

4、字符和Unicode 码的转换 , 虽然只是很简单的几句程序语言,但是缺乏练习的我编写起来还是很费力,最后虽然能按照要求显示结果,但是我知道这些语句还有很多不足或者说是错误的地方,在今后的学习当中,我还得花更多的时间来学好 java.3“Java 语言程序设计”实验报告实验 3刘黎(12271012) 电子信息工程学院 2014-10-20六、 实验要求七、 实验环境 实验地点:东校区机房 实验时间:2014 年 10 月 20 日 操作系统:Windows7 JDK 版本:八、 程序源代码import java.util.Scanner;public class Testpublic sta

5、tic void main(String args)int myID;String myName;Scanner sc1 = new Scanner(System.in);myName = sc1.next();myID = sc1.nextInt();sc1.close();System.out.printf(我叫%s,我的学号是%dn,myName,myID);System.out.printf(我姓%c,我的名字是%cn,myName.charAt(0),myName.charAt(1);char mychar = myName.toCharArray();System.out.prin

6、tf(%c(%x)%c(%x)n,mychar0,(int)mychar0,mychar1,(int)mychar1);System.out.printf(我的学号变换后是:%d,myID);九、 程序运行结果4十、 问题和总结在本次实验中,我发现自己对字符串操作的各种指令还不熟悉,Unicode 编码转换也没好好掌握,课后我还要多多练习 java 文本的输入输出。“Java 语言程序设计”实验报告实验 4.2姓名 刘黎学号 12271012学院 电信2014 年 11 月 4 日十一、 实验要求实验 4.2十二、 实验环境 实验地点:东区机房 实验时间:2014 年 11 月 3 日 操作系

7、统:Windows7 JDK 版本:5十三、 程序源代码/* To change this template, choose Tools | Templates* and open the template in the editor.*/package test4;/* author YFJF*/import java.util.*;public class Test4 /* param args the command line arguments*/public static void main(String args) String xArray = new String200;Str

8、ing x;char xc;boolean isOK = true,isDigit,isLetter;int xNum = 0,j = 0;Scanner sc = new Scanner(System.in);x = sc.nextLine();sc.close();x = x.replace(, );x = x.replace(., );x = x.replace(!, );x = x.replace(?, );x = x.toLowerCase();System.out.println(x);for(int i = 0 ; i= a&xc=0&xc=0isLetter = (x.char

9、At(0)=a6for(int i=1 ; i=a&xc=0&xc=0isLetter =(xc=zSystem.out.println(isOK=+isOK);sc = new Scanner(x);while(sc.hasNext()xArrayxNum = sc.next();xNum +;Arrays.sort(xArray,0,xNum);/* for(int j = 0;jiBj)temp=iBi;iBi=iBj;iBj=temp;System.out.println(数组 iB 排序后的的元素输出: + Arrays.toString(iB);for(i=0;i24);bx +=

10、-+ byteBinaryString(byte)(i16);bx +=-+ byteBinaryString(byte)(i8);bx +=-+ byteBinaryString(byte)i);return bx;public static String intHexString(int i)String bx;bx = byteHexString(byte)(i24);bx +=-+ byteHexString(byte)(i16);bx +=-+ byteHexString(byte)(i8);bx +=-+ byteHexString(byte)i);return bx;3、Stri

11、ngDemo 类package stringdemo;/* author founder*/public class StringDemo /* param args the command line arguments*/16public static void main(String args) / TODO code application logic herebyte i = -1;ByteString a1 = new ByteString();NumberString a2 = new NumberString();System.out.println(a1.byteBinaryS

12、tring(i);System.out.println(a1.byteHexString(i);System.out.println(a2.intBinaryString(i);System.out.println(a2.intHexString(i);三十、 程序运行结果17三十一、 问题和总结这次实验上机是练习类的继承,以及在继承的类里使用被继承类的方法和构造新的方法,并在主函数中使用。在 Java 对象与类的学习上,我认识的还是比较全面的,掌握了一些 java 面向对象的特点,正在逐渐适应这种面向对象的编程方式。另外,在这个实验里我还学到了 int 类型二进制和十六进制字符转换的方法。“

13、Java 语言程序设计”实验报告实验 7.218姓名 刘黎学号 12271012学院 电信2014 年 12 月 15 日三十二、 实验要求实验 7.2三十三、 实验环境 实验地点:东区机房 实验时间:2014 年 12 月 15 日 操作系统:Windows7 JDK 版本:三十四、 程序源代码1、BtyeString 类package stringdemo;/* author founder*/public class ByteString public static String byteBinaryString(byte aByte)String bx = 0000000+ Integ

14、er.toBinaryString(aByte);return bx.substring(bx.length()-8);public static String byteHexString(byte aByte)String bx = 0+ Integer.toHexString(aByte);return bx.substring(bx.length()-2).toUpperCase();2、NumberString 类public class NumberString implements IntegerStringint aInt;19Overridepublic String intB

15、inaryString()String is;ByteString bs = new ByteString();bs.aByte = (byte)(aInt24);is = bs.byteBinaryString();bs.aByte = (byte)(aInt16);is = is+-+ bs.byteBinaryString();bs.aByte = (byte)(aInt8);is = is+-+ bs.byteBinaryString();bs.aByte = (byte)aInt;is = is+-+ bs.byteBinaryString();return is;public String intHexString()String is; ByteString bs = new ByteString();bs.aByte = (byte)(aInt24);is = bs.byteHexString();bs.aByte =

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

当前位置:首页 > 建筑/环境 > 综合/其它

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