标签:
2016-06-24
1、HelloWorld.java
package com.HelloWorld; public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
2、变量
package com.Test; public class Test { public static void main(String[] args) { System.out.println("Define a variable a is "); int a; //声明变量a a = 5; System.out.println(a); //打印一个整数a } }
3、运算符
package com.Test; public class Operator { public static void main(String[] args) { int a,b,c,d; a = 6 + 7; System.out.println("a = " +a); b = a % 5; System.out.println("b = " +b); c = b++; System.out.println("b++后 b = "+b); System.out.println("c = "+c); d = ++b; System.out.println("++b后 b = "+b); System.out.println("d = "+d); } }
4、比较运算符
package com.Test; public class Compare { public static void main(String[] args) { int a = 1; double b = 7.2; String str1 = "hello"; String str2 = "CenLiang"; System.out.println("a等于b: "+(a == b)); System.out.println("a大于b: "+(a > b)); System.out.println("a小于等于b: " + (a <= b)); System.out.println("str1等于str2: "+(str1 == str2)); } }
5、逻辑运算符
package com.Test; public class Logic { public static void main(String[] args) { boolean a = true; // a同意 boolean b = false; // b反对 boolean c = false; // c反对 boolean d = true; // d同意 System.out.println(a&&b); System.out.println(a||b); System.out.println((!a)); System.out.println((c^d)); } }
标签:
原文地址:http://www.cnblogs.com/cenliang/p/5614851.html