标签:
short s1=1;s1=s1+1有什么错?short s1=1;s1+=1;有什么错?
1 import java.util.Random; 2 3 public class ForEachFloat { 4 public static void main(String[] args) { 5 Random rand = new Random(47); 6 float f[] = new float[10]; 7 for(int i = 0; i < 10; i++) { 8 f[i] = rand.nextFloat(); 9 } 10 for(float x : f) { 11 System.out.println(x); 12 } 13 } 14 }
1 public class Flower { 2 int petalCount = 0; 3 String s = "initial value"; 4 5 Flower(int perals) { 6 petalCount = perals; 7 System.out.println("Constructor w/ int arg only, petalCount= " + petalCount); 8 } 9 10 Flower(String ss) { 11 System.out.println("Constructor w/ int arg only, s= " + ss); 12 s = ss; 13 } 14 15 Flower(String s, int petals) { 16 this(petals); 17 //! this(s); //不能调用两个! 18 this.s = s; 19 System.out.println("String & int args"); 20 } 21 22 Flower(){ 23 this("hi", 45); 24 System.out.println("default constructor (no args)"); 25 } 26 27 void printPetalCount() { 28 //! this(11); //不能在构造器之外的任何方法中调用构造器 29 System.out.println("petalCount = " + petalCount + " s = " + s); 30 } 31 32 public static void main(String[] args) { 33 Flower x = new Flower(); 34 x.printPetalCount(); 35 } 36 }
标签:
原文地址:http://www.cnblogs.com/xiongxuesong/p/4559981.html