Java-thinking in Java Chapter 2nd Practice

Source: Internet
Author: User

Thinking in JAVA1
//: Object/hellodate.java/** * Default Initialize class. * @author C.l.wang * @author Caroline Wendy * @version 1.0 */ Public  class Main extends showproperties {    /** * ENTRV point to Class & application. * @param args Array of string arguments * @throws java.lang.Exception No Exceptions thrown */     Public Static void Main(string[] args) {Defaultinit di =NewDefaultinit (); System.out.println ("Default int ="+ Di.i +", Default char ="+ DI.C); }/** * Output: * Default int = 0, default char = *///:~}
2
//: Object/hellodate.java/** * Say Hello World * @author C.l.wang * @author Caroline Wendy * @version 1.0 * * Public  class Main extends showproperties {    /** * ENTRV point to Class & application. * @param args Array of string arguments * @throws java.lang.Exception No Exceptions Thrown * /     Public Static void Main(string[] args) {System.out.println ("Hello, World"); }/** * Output: * Hello, World *///:~}
3
public   Class  Atntest {public  static  void  main  (string[] args) {class Atypename {int  i;         double  D;         Boolean B; void  Show () {System.            Out . println (i); System.            out . println (d); System.         out . println (b);      }} atypename A = new  atypename ();      A.I = 3 ;      A.D = 2.7 ;      A.B = false ;   A.show (); }}
4&5
//: Object/dataonlytest.java//TIJ4 Chapter Object Exercise 4 page//Turn The DataOnly code fragments into a program that compiles and runsClass DataOnly {intIDoubleDBooleanbvoidShow () {System.out.println (i);      System.out.println (d);  System.out.println (b); }} Public  class dataonlytest {   Public Static void Main(string[] args) {DataOnly data =NewDataOnly (); DATA.I = -; DATA.D =1.1; DATA.B =false;  Data.show (); }}/*** output:* 47* 1.1* false*///:~
6
//: Storagetest.java/** * Storage bytes * Created by Wangchenlong on 15/7/6. * * Public  class storagetest {    /** * Number of bytes in String * @param s String * @return bytes * *     Public Static int Storage(String s) {returnS.length () *2; } Public Static void Main(string[] args) {String s ="Caroline"; SYSTEM.OUT.PRINTLN (S +"number of bytes occupied:"+ Storage (s)); }/** * Output: * Caroline bytes Occupied://:~}
7
//: Incrementabletest.java/** * Static variable Test * Created by Wangchenlong on 15/7/6. * *Class Statictest {Static inti = -;} Class Incrementable {Static voidIncrement () {statictest.i++; }} Public  class incrementabletest {     Public Static void Main(string[] args)        {incrementable.increment (); System.out.println ("number becomes"+ statictest.i); }}/** * Output: * number changed to * *//:~
8
//: Onestatictest.java/** * Static variable Single instance test * Created by C.l.wang on 15/7/6. * * Public  class onestatictest {     Public Static void Main(string[] args) {Statictest S1 =NewStatictest (); Statictest s2 =NewStatictest ();//noinspection accessstaticviainstanceSystem.out.println ("s1.i ="+ s1.i +", s2.i ="+ s2.i); Incrementable.increment ();//noinspection accessstaticviainstanceSystem.out.println ("after increment:"+"s1.i ="+ s1.i +", s2.i ="+ s2.i); }}/** * Output: * s1.i = +, s2.i = * after increment:s1.i = $, s2.i = *///:~
9
//: Autoboxtest.java/** * Basic type and wrapper type * Created by C.l.wang on 15/7/6. * * Public  class autoboxtest {     Public Static void Main(string[] args) {Booleanb =false;Charc =' x ';bytet =8; Shorts = -;inti = +;LongL = -;floatf =0.32FDoubleD =0.64;        Boolean B = b; System.out.println ("Boolean b ="+ b); System.out.println ("Boolean B =", e);        Character C = C; System.out.println ("char c ="+ c); System.out.println ("Character C ="+ C);        Byte t = t; System.out.println ("byte t ="+ t); System.out.println ("Byte T =", s);        Short S = s; System.out.println ("Short s =", T); System.out.println ("Short S =", t);        Integer i = i; System.out.println ("int i ="+ i); System.out.println ("Integer I =", n);        Long L = l; System.out.println ("Long L =", K); System.out.println ("Long L ="+ L);        Float f = f; System.out.println ("Float f ="+ f); System.out.println ("Float F =", a);        Double d = d; System.out.println ("Double d ="+ D); System.out.println ("Double D =", c); }}/** * Output: * ... * *//:~
10
//: Commentlinetest.java/** * command Line Parameters * Created by C.l.wang on 15/7/6. * * Public  class commandlinetest {     Public Static void Main(string[] args) {if(Args.length! =3) {System.out.println ("Less than 3 parameters");return; The String result =""; for(String S:args) {result + = s +" "; } System.out.println ("Parameters:"+ result); }}/** * Output: * parameter: Caroline Wendy girl *///:~
11
//:allthecolorsoftherainbow/** * Coded style test * Created by C.l.wang on 15/7/6. * * Public  class rainbowtest {     Public Static void Main(string[] args) {Allthecoloroftherainbow ATC =NewAllthecoloroftherainbow (); Atc.changethehusofthecolor ( -); System.out.println ("Thehueofthecolor ="+ Atc.thehueofthecolor); System.out.println ("anintegerrepresentingcolors ="+ Atc.changeanintegerrepresentingcolors ( +)); }}class Allthecoloroftherainbow {intAnintegerrepresentingcolors;intThehueofthecolor;voidChangethehusofthecolor (intNewhue) {thehueofthecolor = Newhue; }intChangeanintegerrepresentingcolors (intThehueofthecolor) {returnAnintegerrepresentingcolors = Thehueofthecolor; }}/** * Output: * Thehueofthecolor = * Anintegerrepresentingcolors = * *//:~
12&13&14&15

Reference: http://blog.csdn.net/caroline_wendy/article/details/46779719

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java-thinking in Java Chapter 2nd Practice

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.