




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JAVA语言程序设计实验报告实验一:JAVA基本语法班级:计算机083 姓名:陈晓旭 学号:200810214303 日期:2011.05.06一、实验目的1.掌握各种数据类型及其使用方法2.掌握定义变量的方法3.掌握各种运算符的使用及其优先级控制4.掌握字符串操作的常用方法5.掌握基本语句的使用方法6.掌握方法的定义与调用7.掌握数组的定义与使用方法二、 实验内容(实验步骤)题目1.分别运行以下四个独立程序,并解释标红色的语句执行结果。程序1:/package org.cxx.homework01;public class SimpleTypes public static void main(String args) byte b = 055;short s = 0x55ff;int i = 1000000;long l = 3615L;char c = c;float f = 0.23F;double d = 0.7E-3;boolean bool = true;byte g = (byte) 255;System.out.println(b= + b);/ b=055,0作为前缀,所以为8进制,055转换为10进制等于45,故标准输出为45System.out.println(s= + s);/ 0X作为前缀,所以为16进制,0x55ff转换为10进制等于,故标准输出为22015System.out.println(i= + i);System.out.println(l= + l);System.out.println(c= + c + 0);System.out.println(f= + f);System.out.println(d= + d);/ 0.7E-3 不是标准的科学计数法,标准输出则自动转换为7.0E-4System.out.println(bool= + bool);System.out.println(g= + g);/ g 被强制转换为字节型,255为1111 1111 字节型最高位程序2:/package org.cxx.homework01;public class ArithmaticOp public static void main(String args) int a = 5 + 4;int b = a * 2;int c = b / 4;int d = b - c;int e = -d;int f = e % 4;double g = 20.0;double h = g % 4;int i = 3;int j = i+;int k = +i;System.out.println(a= + a);System.out.println(b= + b);System.out.println(c= + c);System.out.println(d= + d);System.out.println(e= + e);System.out.println(f= + f);System.out.println(g= + g);System.out.println(h= + h);System.out.println(i= + i);/ i 初始值为3,执行了j=i+,之后 i=4,j=3, k=+i 是/ 先加后赋值, 故,i=5 k=5;System.out.println(j= + j);System.out.println(k= + k);程序3:/package org.cxx.homework01;public class RelationAndConditionOp public static void main(String args) int a = 25, b = 3;boolean d = a 5);System.out.println(d); / & 优先度 低于 运算符, 高于!=,因为e等于3,故e不等于 0 , 又因为 a/35/ ,故两个都为真,因为d为布尔型 所以输出 trueint f = 2;d = (d | a / f 5);System.out.println(d); / 为或运算 ,因为d之前为真,且a/f5也为真,而或运算/ 要求至少一个为真,则输出为真,因此输出 真程序4:/package org.cxx.homework01;public class MethodsOfString public static void main(String args) String str = I like java programming;int i1 = str.indexOf(j);String s1 = str.substring(i1);String s2 = str.substring(i1, i1 + 4);int i2 = str.lastIndexOf(j);String s3 = str.substring(i2 + 5);System.out.println(s1= + s1);System.out.println(s2= + s2);System.out.println(s3= + s3);/*str.substring()函数 为获得一个字符串的字串,s3 = str.substring(i2+5) 表示在 i2后面的第五个字母开始,而i2= str.lastIndexOf(j); 意思为字符串的后面数,第一个 j开始。*/*题目2:编写程序,实现输入学生的成绩等级,给出相应的成绩范围。设A级为80分以上(包括80分); * B级为70分以上(包括70分);C级为60分以上(包括60分);D级为60分以下。*/package org.cxx.homework01;import java.io.*;public class ChoseLeve public static void main(String args) BufferedReader buf = null;buf = new BufferedReader(new InputStreamReader(System.in);String str = null;do System.out.print(Input the score level:);try str = buf.readLine(); catch (IOException e) e.printStackTrace();if (str.equals(A) System.out.print(str + : the score is 80 upn); else if (str.equals(B) System.out.print(str + : the score is 70 upn); else if (str.equals(C) System.out.print(str + : the score is 60 upn); else if (str.equals(D) System.out.print(str + : the score is 60 downn); else System.out.print(Error.); while (!str.equals(E);/*题目3:编写程序,计算1!+2!+3!+10!,要求具有独立函数计算n!。*/package org.cxx.homework01;public class MultiplyDemo public static void main(String args) int temp0;int temp1 = 0;for(int i = 1;i = 10;i+)temp0 = 1;for(int j = 1;j 0 & flag; i-) for (int j = 0; j aj + 1) flag = true;temp = aj;aj = aj + 1;aj + 1 = temp;System.out.println(n= Sort after =);print(a);private static void
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年铁路劳动安全试题题库及答案
- 2025年新版航空维修实操考试题及答案
- 2025年会计电算化考试题库及答案
- 美术教育知识试题及答案
- 高校非教学岗合同模板(3篇)
- 总监理的面试题库及答案
- 高速公路标牌施工合同(3篇)
- 高企认定合同模板(3篇)
- SMT安全知识考试题及答案
- 民间借贷居间服务合同范本(含知识产权许可协议)
- 《公务员法解读》课件
- 《康复科病人营养治》课件
- 航空质量意识培训
- 中国低空经济城市发展指数(LCDI) 2025(发布版)
- 2024电力工程质量管理试题与答案
- 学习委员的竞选发言稿模版
- 诊疗规范培训课件
- 助贷电销知识培训课件
- 《风力发电培训》课件
- 焊工作业(初训、复审)培训课件
- (完整版)高考英语词汇3500词(精校版)
评论
0/150
提交评论