java程序设计报告答案_Java语言程序设计实验报告

《Java语言程序设计实验报告》由会员分享,可在线阅读,更多相关《Java语言程序设计实验报告(25页珍藏版)》请在人人文库网上搜索。

1、本科实验报告课程名称: Java语言程序设计 实验地点: 致远楼 专业班级: 软工1507班 学号:2015005682学生姓名: 李俊慧 指导教师: 李君婵 实验名称实验一 Java语言基础实验目的1通过实验,掌握Java语言程序设计的基本方法。2学会Java语言中标示符的命名、运算符和表达式的应用。3熟练地掌握Java程序流程控制语句的应用。实验内容1. 编写应用程序,计算100(含100)以内所有偶数的和。2. 编写一个程序,求1-100间的素数。3. 使用for循环语句,编写程序输出以下图案。实验记录1. public class Javashiyan1_1 public static。

2、 void main(String args) int sum=0,i;for(i=1;inumm1+1) temp=numm1+1;numm1+1=numm1;numm1=temp;for(n=0;nb?ac?a:c:bc?b:c;min = ac?bc?c:b:ab?b:a;System.out.println(Max: +max+ Min: +min);public static void main(String args) Javashiyan3_3 A = new Javashiyan3_3();Javashiyan3_3 B = new Javashiyan3_3();Javash。

3、iyan3_3 C = new Javashiyan3_3();Javashiyan3_3 D = new Javashiyan3_3();Javashiyan3_3 E = new Javashiyan3_3();Javashiyan3_3 F = new Javashiyan3_3();A.Compare(12,23,34);B.Compare(40,23,94);C.Compare(12,83,34);D.Compare(42,73,34); E.Compare(99,67,8);F.Compare(99,2,40);4. public class Javashiyan3_4 publi。

4、c static void main(String args) Goods A = new Goods(Dong_Bei_ Rice,12.0,Heilongjiang);Goods B = new Goods(Te_lun_su_milk,63,China);System.out.println(-A.ShowMe()-);A.ShowMe();/ 显示A商品的名称价格产地System.out.println(-A.Add(20)-);A.Add(20);/ 上架20份A.ShowMe();System.out.println(-A.Sale(10)-);A.Sale(10);/ 销售10份。

5、A.ShowMe();System.out.println(-A.check()-);A.check();System.out.println(-A.query()-);A.query();B.ShowMe();B.Add(50); B.query();B.Sale(50);B.query();class Suppermarket String Merchandise = new String100;public void check() /*int t1;for(t1=0;Merchandiset1!=null;t1+) System.out.print(Name:+Merchandiset。

6、1);System.out.print( Inventory:+P.Inventory); */public void query() /*P.ShowMe();System.out.print( Inventory:+P.Inventory); */ class Goods extends Suppermarket String Name;double Price;String Producer;int Inventory,t=0;/ 表示货架上的数量public Goods() public Good

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java程序设计实验报告 实验一 实验题目:从键盘上读入10个字符串存入数组a中,然后输出这10个字符串中最大字符串 和最小字符串。 实验代码: public class StrPro { public static void main(String[] args) { String str[] = new String[5]; System.out.println("Please input 10 strings:"); int i; String max,min; for(i=0;i<5;i++){ System.out.print("Please input the "+(i+1)+" string:"); Scanner sc = new Scanner(System.in); str[i] = sc.nextLine(); } max = str[0]; min = str[0]; for(i=0;i<str.length;i++){ if(max.compareTo(str[i])<0){ max = str[i]; } if(min.compareTo(str[i])>0){ min = str[i]; } } System.out.println("最大的字符串为:"+max); System.out.println("最小的字符串为:"+min); } } 实验结果: 实验心得体会: 掌握了java的基本语法,数组的定义与使用,做这个实验要了解字符串数组的定义 及字符串数组的输入方法,还有比较字符串数组的大小的调用方法等。 实验二 实验题目: 自定义一个矩形类(Rectangle),包含的属性有:长(length),宽(width), 包含的方法有:关于属性的setter和getter方法,即setLength,getLength,setWidth ,getWidth,计算矩形面积的方法(getArea)。 定义矩形类的子类正方形类(Square),包含的属性和方法自行确定,要求完成的 功能是,能计算正方形的面积。 定义一个测试类(Test),测试矩形类和正方形类能否正确的计算面积。 以上类中属性和方法的访问权限自行确定,方法和构造方法若有参数,也自行确定 。 实验代码: public class Rectangle { int Length; int Width; public int getLength() { return Length; } public void setLength(int length) { Length = length; } public int getWidth() { return Width; } public void setWidth(int width) { Width = width; } int getArea(){ return Length * Width; } } public class Square extends Rectangle{ Square(int border) { super.setLength(border); super.setWidth(border); } } public class Test { public void test(){ System.out.println("请选择计算的形状的序号:1.矩形 2.正方形"); Scanner sc = new Scanner(System.in); int i = sc.nextInt(); int len,wid; if(i==1){ System.out.print("请输入矩形的长:"); Scanner s = new Scanner(System.in); len = s.nextInt(); System.out.print("请输入矩形的宽:"); wid = s.nextInt(); Rectangle re = new Rectangle(); re.setLength(len); re.setWidth(wid); System.out.println("矩形面积为:"+re.getArea()); } else if(i==2){ System.out.print("请输入正方形的边长:"); Scanner s = new Scanner(System.in); len = s.nextInt(); Square sq = new Square(len); System.out.println("正方形面积为:"+sq.getArea()); } else{ System.out.println("输入错误!"); } } public static v

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值