




已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验16:字符串数组复制1目的:掌握java中数组复制的方法public class ArrayCopyDemo public static void main(String args) char copyFrom=d,e,c,a,f,f,e,i,n,a,t,e,d; /源数组的声明及初始化 char copyTo = new char7; /目的数组对象的创建 System.arraycopy(copyFrom, 2, copyTo, 0, 7);/调用数组复制方法 System.out.println(new String(copyTo);/结果输出实验1:基本数据类型的变量的赋值1目的:掌握基本数据类型的声明及初始化规则public class Assign public static void main (String args ) int x, y; /声明整型变量 float z=3.414f ; /声明并赋值float型变量 double w=3.1415; /声明并赋值double型变量 boolean truth=true; /声明并赋值boolean型变量 char c; /声明字符变量 String str; /声明string类变量 String str1=bye; /声明并赋值string类变量 c=A; /给字符变量赋值 str=Hi out there; /给string变量赋值 x=6; y=1000; /给int型变量赋值 System.out.println(x=+x); System.out.println(y=+y); System.out.println(z=+z); System.out.println(w=+w); System.out.println(truth=+truth); System.out.println(c=+c); System.out.println(str=+str); System.out.println(str1=+str1); 实验5:移位运算1目的:掌握位逻辑运算符&、|的使用规则及目的public class BitwiseDemo static final int VISIBLE=1;/定义常量值 static final int DRAGGABLE=2; static final int SELECTABLE=4; static final int EDITABLE=8; public static void main(String args) int flags=0; flags=flags|VISIBLE;/对flags的最低位置值 flags=flags|DRAGGABLE;/对flags的次低位置值 if(flags&VISIBLE)=VISIBLE) if(flags&DRAGGABLE)=DRAGGABLE) System.out.println(Flags are Visible and Draggable); flags=flags|EDITABLE;/对flags的倒数第4位置值 if(flags&EDITABLE)=EDITABLE) System.out.println(Flags are now also Editable); 实验13:复制字符串1目的:掌握while语句对程序的控制机制public class Fuzhi public static void main(String args) String copyFromMe = Copy this string until you encounter the letter g.; /声明源数组并初始化 StringBuffer copyToMe = new StringBuffer();/创建目的数组的对象 int i = 0; char c = copyFromMe.charAt(i); /对源数组进行单个取值 while (c != g) copyToMe.append(c); /向目的数组添加元素 c = copyFromMe.charAt(+i); System.out.println(copyToMe); 实验17:与的区别1目的:熟悉并掌握与的区别及用法public class QuBie public static void main(String args) int a=-64,b=32,c,d; c=a2;/带符号的右移 d=b2;/不带符号的右移 System.out.println(a =+a); System.out.println(b=+b); System.out .println(a移位后是:+c); System.out .println(b移位后是:+d);实验7:按照格式输出结果1目的:理解并掌握java语言的输出调用public class FormatPrint public static void main(String args) int i=1,j=1; /循环变量初始化 for(i=1;i7;i+) /外层循环,控制行输出 for(j=1;j=i;j+) /内层循环,控制列输出 System.out.print(* ); System.out.println(); /换行输出 实验14:for语句输出数组元素1:目的:进一步熟悉二维矩阵的创建及初始化;掌握使用for语句对程序流进行控制public class ShuChu public static void main(String args) int aMatrix = new int4;/创建二维数组的对象 for (int i = 0; i aMatrix.length; i+) aMatrixi = new int5;/为矩阵的列创建对象 for (int j = 0; j aMatrixi.length; j+) aMatrixij = i + j; /对二维矩阵各个元素赋值 for (int i = 0; i aMatrix.length; i+) for (int j = 0; j 50) y=9; z=x+y; System.out.println(x=+x+y=+y+z=+z);实验3:一元运算符目的:掌握一元运算符的使用规则public class TestUnary public static void main(String args) int a=9,b=-a;/“-”的优先级较高 byte bb=9; int ib=+bb;/相当于“ib=ib+bb” int x=4,y=8; int z,i=0; int j=i+; int k=+j; z=(x+)*(-y);/括号优先级最高 System.out.println(a=+a); System.out.println(b=+b); System.out.println(bb=+bb); System.out.println(ib=+ib); System.out.println(i=+i); System.out.println(j=+j); System.out.println(k=+k); System.out.println(x=+x); System.out.println(y=+y); System.out.println(z=+z);实验6:用while语句输出1000以内的奇数目的:掌握while语句的使用规则public class WhileDemo public static void main(String args) int i=1; /循环变量i初始化为1 while(i1000) /指定继续条件 System.out.print(i+ ); i+=2; /改变循环变量 /循环体 实验12:小写变大写目的:学会使用for循环对数组进行操作public class XiaoToDa public static void main(String args) String anArray = String One, String Two, String Three ;/创建数组并初始化for (int i = 0; i = 90) /if后的括号里的值必须是boolean型的 grade = A; else if (testscore = 80) grade = B; else if (testscore = 70) grade = C; else if (testscore = 60) /else if语句可以有多个 grade = D; else /else语句只能有一个 grade = F; System.out.println(Grade = + grade); 实验15:创建字符串数组并输出目的:掌握二维数组的创建及初始化方法public class ArrayOfArrayDemo2 public static void main(String args) String cartoons=Flintstones,Fred,Wilma,Pebbles,Dino ,Rubbles,Barney,Betty,Bam Bam,Jetsons,George,Jane,Elroy ,Judy,Rosie,Astro,Scooby Doo Gang,Scooby Doo,Shaggy,Velma,”Fred,Daphne;/创建二维字符串数组并初始化 for(int i=0;icartoons.length;i+) System.out.print(cartoons+i+,+cartoonsi.length+elements:); for(int j=0;jcartoonsi.length;j+) System.out.print(cartoon
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025至2030年中国冷冻蔬菜行业发展趋势预测及投资战略咨询报告
- 推拿治疗学测试题附答案详解(综合卷)
- 2025版离婚房产分割与个人财产界定合同范本
- 2025电商农产品上行合作协议书
- 2025版离婚协议签订后的共同生活费用分担合同
- 2025年数据中心防排烟系统施工与调试合同
- 2025年度企业市场拓展与品牌战略咨询协议
- 2025版装配式砌墙施工技术交流合作合同
- 2025年有限责任公司股东风险管理与责任承担协议
- 2025年度教育培训机构课程开发与推广委托服务合同样本
- 聚合工艺作业培训课件
- 千人相亲活动方案
- 消防避火服课件教学
- 土地法学教学课件电子教案课件
- 儿童银行开业活动方案
- 小学二年级上册心理健康教案(适合北京教育出版社)
- CJ/T 43-2005水处理用滤料
- 无人机技能培训课件
- 数据标注项目管理制度
- 如何写好作文开头结尾 课件
- 回收拆除废旧设备合同协议书
评论
0/150
提交评论