实验二、数值类型与变量声明

上传人:kms****20 文档编号:46708787 上传时间:2018-06-27 格式:PDF 页数:4 大小:328.29KB
返回 下载 相关 举报
实验二、数值类型与变量声明_第1页
第1页 / 共4页
实验二、数值类型与变量声明_第2页
第2页 / 共4页
实验二、数值类型与变量声明_第3页
第3页 / 共4页
实验二、数值类型与变量声明_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《实验二、数值类型与变量声明》由会员分享,可在线阅读,更多相关《实验二、数值类型与变量声明(4页珍藏版)》请在金锄头文库上搜索。

1、实验二、数值类型与变量声明 实验数据记录及分析(或程序及运行结果) 請完成及記錄下列各題: (1) 分析以下代码会打印哪些内容,通过程序验证自己的判断并在报告中说明: 1. public class DataType (2) 利用输出语句来实现数据格式化显示 1. 在横线上填出下列变量的定义类型 写出变量的定义类型并解释“+”在输出语句中的作用是什么? (3) 调试运行 class TypeConversion后解释画线语句的含义(注意:类型之间的转换) 。 public class DataType public static void main(String args) int i=123

2、4578900+987543210; System.out.println(i); long j=1234578900+987543210; System.out.println(j); long k=1234578900+987543210L; System.out.println(k); long l=1234578900L+987543210L; System.out.println(l); public class Example1 public static void main(String args) x=45; y=3.14f; z=3.1415; truth=true; c=6

3、; System.out.println(“各变量的值是:“); System.out.println(“x 的值是:“+x); System.out.println(“y 的值是:“+y); System.out.println(“z 的值是:“+z); System.out.println(“truth 的值是:“+truth); System.out.println(“c 的值是:“+c); (4) 请依据所提供的答案,利用并组合 c, i, +, s 各四字符完成横线空白,通过程序 验证自己的判断并在报告中说明: 1. public class CharSample (5) 请解释下列

4、转义字符意义,并撰写程序利用转义字符完成下述结果 转义字符: t n r ” 结果: public class TypeConversion public static void main (String args) char a=1; int b=4; double c=24.6f; byte d; d=(byte)(a+b+c); /(1) short e; e=(short)(a+b+c); /(2) double g; g=a+b+c; /(3) System.out.println(“d=“+d); System.out.println(“e=“+e); System.out.pri

5、ntln(“g=“+g); public class CharSample public static void main(String args) System.out.println(“H“+“Bird“); System.out.println(H+“Bird“); String s=“; char c=65; int i=1; System.out.println(_); System.out.println(_); System.out.println(_); System.out.println(_); System.out.println(_); System.out.print

6、ln(_); System.out.println(_); System.out.println(_); System.out.println(_); _=_; System.out.println(s); _=_; System.out.println(s); HBird HBird A 1 66 A 67 B 1 B1 67 1 1B (6) 上机输入程序并依照个小题要求调试运行程序 1. 写出程序运行的结果 2. 修改上述程序,定义一个字符型变量,并定义其初值为a,然后输出该变 量的值,在下面写出修改后的代码片段。 3. 修改上述程序,定义一个字符型变量,并定义其初值为 100,然后输出

7、该 变量的值,在下面写出修改后的代码片段。 4. 修改上述程序,定义一个字符型变量,并定义其初值为 65536,然后输出 该变量的值,在下面写出修改后的代码片段,如果有错误,说明原因。 5. 修改上述程序,定义一个单精度类型的变量,并定义其初值为 10.0,然后 输出该变量的值,在下面写出修改后的代码片段。 6. 修改上述程序,定义一个双精度类型的变量,并定义其初值为 10.0,然后 输出该变量的值,在下面写出修改后的代码片段。 Java Object-Oriented Software Design Java Object-Oriented Software Design Java Obje

8、ct-Oriented Software Design “JavaObject-Oriented Software Design“ JavaObject-Oriented Software Design JavaObject-Oriented Software Design public class Variable public static void main(String args) int a=10; System.out.println(“a=“+a); 7. 替换下面的代码段到上述程序,分析现象。 结果为 8. 替换下面的代码段到上述程序,分析结果。 结果为 9. 声明一个布尔类型

9、的变量,其初值为真。 10. 替换下面的代码段到上述程序,分析现象。 (7) 将输入的华氏温度 78 度转换为摄氏温度,转换成的摄氏温度在屏幕上显示 出来,转换公式为:摄氏度=(5/9)*(华氏度-32) (8) 输出字母C对应的 ASCII 码表中十进制的数值; float f=10.0f; double d=100.0d; f=d; System.out.println(“f=“+f); int a=10; char c=a; a=c+a; System.out.printf(“c=%c“,a); Variable v=new Variable(); System.out.println(“v=“+v);

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

当前位置:首页 > 生活休闲 > 科普知识

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