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

这篇博客详细记录了北京交通大学学生刘黎进行的Java语言程序设计实验,包括多个实验部分,涉及字符、Unicode编码、输入输出操作、字符串处理、数组、类的继承以及接口的使用。实验中,博主通过编写和运行程序,实践了Java的基本语法和功能,认识到需要加强字符串操作和Unicode转换的练习。
摘要由CSDN通过智能技术生成

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

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

2、m.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.toHexString(myName0)+ +Integer.toHexStr。

3、ing(myName1);System.out.printf(我的名字变成了:);System.out.println(myName);int a,b,c;a = myID/;b = myID%/1000;c = myID%1000;System.out.printf(我的学号的三个段分别是:);System.out.print(a+ +b+ +c);四、 程序运行结果五、 问题和总结今天是第二次java实验上机。这个实验做的是java的输出指令语句练习,其中包括了字符串数组的使用,字符串的连接,字符和Unicode码的转换 ,虽然只是很简单的几句程序语言,但是缺乏练习的我编写起来还是很费力,。

4、最后虽然能按照要求显示结果,但是我知道这些语句还有很多不足或者说是错误的地方,在今后的学习当中,我还得花更多的时间来学好java.“Java语言程序设计”实验报告实验3刘黎() 电子信息工程学院 2014-10-20六、 实验要求七、 实验环境 实验地点:东校区机房 实验时间:2014年10月20日 操作系统:Windows7 JDK版本:八、 程序源代码import java.util.Scanner;public class Testpublic static void main(String args)int myID;String myName;Scanner sc1 = new Sc。

5、anner(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 mycha

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java程序设计实验报告 实验一 实验题目:从键盘上读入10个字符串存入数组a中,然后输出这10个字符串中最大字符串 和最小字符串。 实验代码: public class StrPro { public static void main(String[] args) { String str[] = new String[5]; System.out.println("Please input 10 strings:"); int i; String max,min; for(i=0;i<5;i++){ System.out.print("Please input the "+(i+1)+" string:"); Scanner sc = new Scanner(System.in); str[i] = sc.nextLine(); } max = str[0]; min = str[0]; for(i=0;i<str.length;i++){ if(max.compareTo(str[i])<0){ max = str[i]; } if(min.compareTo(str[i])>0){ min = str[i]; } } System.out.println("最大的字符串为:"+max); System.out.println("最小的字符串为:"+min); } } 实验结果: 实验心得体会: 掌握了java的基本语法,数组的定义与使用,做这个实验要了解字符串数组的定义 及字符串数组的输入方法,还有比较字符串数组的大小的调用方法等。 实验二 实验题目: 自定义一个矩形类(Rectangle),包含的属性有:长(length),宽(width), 包含的方法有:关于属性的setter和getter方法,即setLength,getLength,setWidth ,getWidth,计算矩形面积的方法(getArea)。 定义矩形类的子类正方形类(Square),包含的属性和方法自行确定,要求完成的 功能是,能计算正方形的面积。 定义一个测试类(Test),测试矩形类和正方形类能否正确的计算面积。 以上类中属性和方法的访问权限自行确定,方法和构造方法若有参数,也自行确定 。 实验代码: public class Rectangle { int Length; int Width; public int getLength() { return Length; } public void setLength(int length) { Length = length; } public int getWidth() { return Width; } public void setWidth(int width) { Width = width; } int getArea(){ return Length * Width; } } public class Square extends Rectangle{ Square(int border) { super.setLength(border); super.setWidth(border); } } public class Test { public void test(){ System.out.println("请选择计算的形状的序号:1.矩形 2.正方形"); Scanner sc = new Scanner(System.in); int i = sc.nextInt(); int len,wid; if(i==1){ System.out.print("请输入矩形的长:"); Scanner s = new Scanner(System.in); len = s.nextInt(); System.out.print("请输入矩形的宽:"); wid = s.nextInt(); Rectangle re = new Rectangle(); re.setLength(len); re.setWidth(wid); System.out.println("矩形面积为:"+re.getArea()); } else if(i==2){ System.out.print("请输入正方形的边长:"); Scanner s = new Scanner(System.in); len = s.nextInt(); Square sq = new Square(len); System.out.println("正方形面积为:"+sq.getArea()); } else{ System.out.println("输入错误!"); } } public static v
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值