第二周博客
- 第二周博客 推荐度:
- 相关推荐
第二周博客
1.小练习
本周信息学院组织了班级篮球赛,现计科1班,计科2班,电气1班,电气2班
各有7,6,8,9名球员,现在需要设计一个程序计算出从他们当中选出5名参赛选手组成新的一支球队代表学院参加比赛,总共有多少种结果
public class Player{public static void main(String[] args) {int a = 7, b = 6, c = 8, d = 9, i = 0;//四个班各有7,6,8,9名球员for (int x = 0; x <= a; x++) {for (int y = 0; y <= b; y++) {for (int z = 0; z <= c; z++) {for (int m = 0; m <= d; m++){if (x + y + z + m == 5) {//总共选出五名球员System.out.println("计科1班 " + x + "\t计科2班 " + y + "\t电气1班 " + z +"\t电气2班" + m);i++;}}}}}System.out.println("有" + i + "结果")//计算出有多少种结果}
2.作业中的错题
程序分析题
public class Test01 {public static void main(String[] args){byte b = 3;b = b + 4;System.out.println("b="+b);}
}
此代码在编译器上无法编译成功,显示为不兼容,正确代码如下
public class Test01 {public static void main(String[] args){int b = 3;b = b + 4;System.out.println("b="+b);}
}
因为 b = b + 4;
中的4的类型默认为int,而不是byte。
public class Test02 {public static void main(String[] args){int x = 12;{int y = 96;System.out.println("x is" + x);System.out.println("y is" + y);}y = x;System.out.println("x is"+x);}
}
此代码在编译器上无法编译成功,x不应分配y,正确代码如下
public class Test02 {public static void main(String[] args){int x = 12;int y = 96;{System.out.println("x is" + x);System.out.println("y is" + y);}System.out.println("x is"+x);}
}
此题中的y是定义在第三个{}内,所以不能在第二个{}内将x分配给y。
最新文章
- Google正在测试最新升级的句法搜索功能
- 亚马逊迫于微软竞争压力调低云服务价格
- Java 接口+继承
- Understanding parameters:理解参数(Parameter)
- 【C#】KPM算法解决字符串匹配问题
- 你了解API测试吗?如何充分的测试一个API?
- C++行为型模式
- Windows上使用ionic开发IOS程序
- jmeter用法
- EmguCV学习(三)
- 【EmguCV】EmguCV各种调用
- 【转帖】Dirichlet Distribution(狄利克雷分布)与Dirichlet Process(狄利克雷过程)原文https:www.datalearner.comblog10514
- 基于Redis的消息中心缓存搭建
- 强制横屏或者竖屏
- 程序员应该学习如何学习
- Hadoop安装与使用
- 【物体检测快速入门系列
- 视频编解码入门知识
- javascript中call的用法总结
- 空指针异常常见原因