随笔分类 -  Java

摘要:Foreach是for语句的特殊简化版本,但任何时候的foreach语句都可以改写成for语句。Foreach语句在遍历数组等方面为程序员提供了很大的方便语法如下: For(元素变量 x:遍历对象obj){ 引用了x的java语句 } 实例: package Foreach1; public cla... 阅读全文
posted @ 2015-03-14 22:05 时间淡无痕 阅读(1927) 评论(0) 推荐(0)
摘要:class Pupil{ Pupil(int age){ System.out.println("Pupil:"+age); } } class Teacher{ Pupil p1=new Pupil(9);... 阅读全文
posted @ 2014-11-10 16:39 时间淡无痕 阅读(288) 评论(0) 推荐(0)
摘要:public class zitest { public static void main(String[] args) { int c,a=10,b=20,x=30,y=40; c=a++; System.out.println("初始值a=10,b=20"); System.out.println(... 阅读全文
posted @ 2014-04-26 10:40 时间淡无痕 阅读(170) 评论(0) 推荐(0)
摘要:public class Logic { public static void main(String[] args) { boolean a,b,c; a=true; b=false; System.out.println("逻辑运算,其中a=TRUE,b=FALSE"); ... 阅读全文
posted @ 2014-04-26 10:13 时间淡无痕 阅读(143) 评论(0) 推荐(0)
摘要:代码中使用1表示闰年,0表示不是闰年 public class leap_years { public static void main(String[] args) { int year = Integer.parseInt(args[ 0]); int leap; if(year%4==0) ... 阅读全文
posted @ 2014-04-26 10:10 时间淡无痕 阅读(245) 评论(0) 推荐(0)
摘要:首先代码如下(记事本编写,文件格式为Java)public class LogicTest{ public static void main(String[] args) { boolean a,b,c; a=true; b=false; c=a&b; System.out.println("a与b的位运算与"+c); c=a|b; System.out.println("a与b的位运算或"+c); c=a^b; System.out.println("a与b的位运算异或:"+c); c=!a; Syste... 阅读全文
posted @ 2013-06-01 10:10 时间淡无痕 阅读(277) 评论(0) 推荐(0)
摘要:主要代码public class Test_3{ public static viod main(String[] args) { int a=0,b=0,c=0; for(int i=100;i<=999;i++) { a=i/100; b=i%100/10; c=i%10; if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==i) { System.out.println(i); } } }}结果如图 <ignore... 阅读全文
posted @ 2013-06-01 10:06 时间淡无痕 阅读(172) 评论(0) 推荐(0)