欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    JAVA基础实验编程.doc

    • 资源ID:29964641       资源大小:193.50KB        全文页数:10页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    JAVA基础实验编程.doc

    Java 实验报告实验日期:2011年10月17日 实验机房与机号: 实验班级: 组员姓名学号: 指导教师:刘寿强 第三单元实验目的:掌握陈述面向对象的思想,通过创建类的实力来体现实验内容:第三单元;实验步骤:3-2class DogString color;int weight;public Dog(String color,int weight)this.color=color;this.weight=weight;public void showd()System.out.println("这是体重为"+weight+"斤,"+"颜色为"+color+"的狗");class CatString color;int weight;public Cat(String color,int weight)this.color=color;this.weight=weight;public void showc()System.out.println("这是体重为"+weight+"斤,"+"颜色为"+color+"的猫");public class Apublic static void main(String args)Dog d1= new Dog("黄色",100);Cat c1= new Cat("白色",200);d1.showd();c1.showc(); 3-3class CarString ping;double price;String date;public Car(String ping,double price,String date)this.ping=ping;this.price=price;this.date=date;public void show()System.out.println(ping+"轿车,价格为"+price+date);public void qd()System.out.println("汽车正在启动");public void sc()System.out.println("汽车正在刹车");public void js()System.out.println("汽车正在加速");public class Apublic static void main(String args)Car car=new Car("奇瑞",3000,"保修终生!");car.show();car.js();3-4public class ConsoleParamspublic static void main(String args)if (args.length<2)return;int a=Integer.parseInt(args0);int b=Integer.parseInt(args1);int c;c=a+b;System.out.println(a+" +"+b+" ="+c);3-5import java.io.*;public class ExampleDpublic static void main(String args)int num=20;if(num>20)System.out.println("数值较大");elseSystem.out.println("数值较小或等于");3-6class SExamstatic int num=0;public SExam() num+;public class StaticExampublic static void main(String args)SExam se1=new SExam();SExam se2=new SExam();SExam se3=new SExam();System.out.println(SExam.num+"次");第四单元目的:掌握格式化转换异常,实验内容:第四单元步骤如下:public class NumberFormatExceptionText /* * param args */public static void main(String args) / TODO Auto-generated method stubint iArray=0,0; try iArray0=Integer.parseInt(args0); iArray1=Integer.parseInt(args1);catch(ArrayIndexOutOfBoundsException e) System.out.println("用户输入的数据不完整,程序使用默认值代替:"); catch(NumberFormatException e) System.out.println("用户输入的不全是数值型的数据,程序使用默认值替代:"); System.out.println(iArray0+"+"+iArray1+"="+(iArray0+iArray1);public class ArithmeticExceptionText /* * param args */public static void main(String args) / TODO Auto-generated method stubtryint a=args.length;int b=42/a;catch(ArithmeticException e)System.out.println("除数不能够为零啊!");import java.util.Random;public class NegativeIndexExceptionDemo public int getNumberOfRandomIndex(int iArray)throws NegativeIndexExceptionRandom random=new Random();int index=random.nextInt();if(index<0) throw new NegativeIndexException(this.getClass().getName()+".getNumberOfRandomIndex(int)方法不能够处理自己所抛出的异常:索引值"+index+"产出异常"); index=index%iArray.length;return iArrayindex;public static void main(String args) int iArray=0,1,3,4,5,6,7,8,9;int randomNumber=0;tryrandomNumber=new NegativeIndexExceptionDemo().getNumberOfRandomIndex(iArray);catch(NegativeIndexException e)System.out.println(e+"nmian方法有能力处理该异常t");randomNumber=Math.round(float)(Math.random()*10);System.out.println("产生随机结果为"+randomNumber);public class NegativeIndexException extends Exceptionpublic NegativeIndexException()super();public NegativeIndexException(String message)super(message);第五单元一、实验目的:熟悉掌握输入输出流二、实验内容:第五单元三、实验步骤 练习5-1 校验用户密码格式(1) 程序代码import java.util.Scanner;public class CheckPWpublic static void main(String args)System.out.println("请输入密码:");Scanner scanner=new Scanner(System.in);String inputString=scanner.nextLine();String regular="a-zA-Z$_a-zA-Z$_0-97,19"if(inputString.matches(regular)System.out.println("密码符合组合规律。");elseSystem.out.println("密码不符合组合规律。");(2) 运行结果图5-1练习5-2 转换中文格式日期(1) 程序代码import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Locale;public class ChineseDatepublic static void main(String args)Date date=new Date(10,9,2011);String dateFormatStr="北京时间:ntH:mm:ssntEntyyyy-M-dd"SimpleDateFormat simpleFormat=new SimpleDateFormat(dateFormatStr);System.out.println(simpleFormat.format(date);(2) 运行结果图5-2练习5-3 万年历(3) 程序代码import java.text.SimpleDateFormat;import java.util.*;public class CalendarAutopublic static void main(String args)System.out.println("请输入年月(格式:年 月):");Scanner scanner=new Scanner(System.in);int params=new int2;for(int i=0;i<2&&scanner.hasNextInt();i+)paramsi=scanner.nextInt();if(params1>12)params1=params1%13;if(params1<0)params1=12+params1%13;Calendar calendar=Calendar.getInstance();calendar.set(params0,params1-1,1);int firstIndex=calendar.get(Calendar.DAY_OF_WEEK)-1;char title='日','一','二','三','四','五','六'int daysArray=new int67;int day=1;for(int i=firstIndex;i<7;i+)daysArray0i=day+;for(int i=1;i<6;i+)for(int j=0;j<7;j+)if(day>daysOfMonth(params0,params1)i=6;break;daysArrayij=day+;for(int i=0;i<7;i+)System.out.print(titlei+"t");System.out.println();for(int i=0;i<6;i+)for(int j=0;j<7;j+)if(daysArrayij!='0')System.out.print(daysArrayij+"t");else System.out.print(" t");System.out.println();private static int daysOfMonth(int year,int month)switch(month)case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:if(year % 4 = 0 && year % 100 !=0) return 29;if(year % 100 = 0 && year % 400 !=0)return 29;return 28;default:return 0;(4) 运行结果图5-310-结0 =0 = 0 % &0= % ( 0 0 ) ) " ) " . ! (+< = (+ ; ) )"+ . +< + ) 0 ( + <0 +< (+= +< ( 六'''三'二''' ) . ( ), , ( ) = )< ( ) . +) & 0 = ) ( )" 式月入( * 代年万-结) ( . ) ( " - 时北 ) 0( ( . 代日式中 -图结)合符码( . )。合组"( . ) ( " ,0 -_- ) ) . ( )码请( . 代格码验 骤单五内出输输:目单) ( ) ( ) +为随" . 0) . . ) 异处能方 ( . ) ( 0= , ,0= ) ( % = )常出 "值常抛己理法 +( ) ( 0< ) ) ) . )!为能" . / = / * * ) +0 "+ + ( ;)替默使据的值不入" . ) ):值默使整不输" ) ; )0 ( = 0= / * * 下单第常异化掌单)"+. ( . ) ) = )( ) +)( 0 )于小数 . )"值 . 0 00 ) * -) +"+( += ) ( . )0 . = < () -).) .)!终"0,奇 = ) ( )速正车( . ) )"正车 ) )"正" . ) ) +格,+ ( )( = . ) ( -) ) ),白 = )0"黄 ) )"" 为"," 重这 ) ) )"+ +色+斤 +重这 )( . ) , -骤元元容体体实过通象面握:单强刘师 号名 班实 机机 日0 期报验0 报 机班 号 强握通体元骤 , ) +斤+ ) 重 "") 黄)=白) ) ( ) = ) (, ) ") 车" .车速 奇终.) ( )+ "+ * 0 0 ) 数) (+ ) ) . ."掌常 0 ( ; 输使) 值默; +"0) * / = 能! . ) 0 )( 法抛值出)=% 0 . 方异) .0 随 ) ( ( 单:内骤 验格 () . 0 ).组。 符合 式 时 ) )-万 (式 = ) .) () = )( ) ''' ( = + + + < . ) +( +( ! ) 0 ( 0% 0 0结 10

    注意事项

    本文(JAVA基础实验编程.doc)为本站会员(豆****)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开