java实验报告_第1页
java实验报告_第2页
java实验报告_第3页
java实验报告_第4页
全文预览已结束

下载本文档

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

文档简介

1 实验 2 基本数据类型和数组实验 一 实验目的一 实验目的 1 学习标识符的命名规则 2 学习基本数据类型变量的声明 初始化 3 学习常量的使用 4 学习算术运算符中的求模 自增 自减运算 5 学习整数除法 浮点数除法和整数与浮点数混合除法运算 6 学习逻辑运算符的与 或 非运算 7 学习字符型 数值型转换的方法 二 实验软件环境二 实验软件环境 jdk1 6 0 02 windows XP 三 实验内容三 实验内容 1 编写一个 java 程序 该程序声明各种基本数据类型的变量 对它们初始 化 再显示它们各自的值 定义一个双精度数据类型的常量 并显示它的值 public class InitVar public static void main String args byte a short b int c long d float e double f char g boolean h double pi 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 圆周率 pi pi 2 使用 javac 编译 InitVar java 程序 程序出错 为什么 应该怎么修改 2 编写一个 java 程序 该程序进行求模 自增和自减运算 public class Arithmetic1 public static void main String args int a 10 int b 6 int s 0 s a b System out println a b s 结果为 分析为什么得到这个 结果 a a 的值现在为 b b 的值现在为 s a b 将 a b 用括号表示出它的运算先后顺序 System out println a a System out println b b System out println s s 3 编写一个 java 程序 该程序进行与 或 非运算 public class Logic public static void main String args boolean a x y z a 5 6 a 的值为 x a x 的值为 y a y 的值为 z x y z 的值为 System out println a a System out println x x System out println y y System out println z z 4 强制类型转换 先运行程序 分析结果 3 public class RealDemo public static void main String args 对于 float 变量进行赋值 小数后面必须加上 f float x 123 456f 对于 double 变量进行赋值 小数后面不一定需要加上 d double y1 23 789 double y2 78 654d 显示结果 System out println x x System out println y1 y1 System out println y2 y2 分析结果 编写一个方法 实现将数组后移一位 比如原数组为 Array 1 2 2 1 0 1 2 2 1 源代码如下 请同学们补充完成程序 public class Array1 public static void main String args Array1 move new Array1 int array1 new int 30 System out println 初始数组为 for int k 0 k 5 k array1 k k 1 System out print array1 k System out println move rightArray array1 System out println 移位后数组为 for int j 0

温馨提示

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

评论

0/150

提交评论