1.1 The difference between the basic data type and the reference data type of the pass parameter:
The parameter passed by the base data type is a value; The parameter passed by the reference data type is an address, such as: Public Static voidMain (string[] args) {//TODO auto-generated Method Stub intA=9; int[] arr={1,2}; intW; System. out. println ("First"-am","+arr[0]+","+arr[1]);//9,1,2Chuandi (A,arr); System. out. println ("Second"-am","+arr[0]+","+arr[1]);//9,1,100 } Public Static voidChuandi (intAint[] arr) {a=a+2; arr[1]= -; System. out. println (A +","+arr[0]+","+arr[1]);//11,1,100 }}
2.. private is a permission modifier
private class animal{ private animal () {} Private animal (data type variable name) {...} public static void method (...) {....}} If the outside world wants to access the method methods in this animal class, you can pass the Animal.method (...)
3. The programming requires the input of the sum of squares of integers a and B, if greater than 100, the output of more than hundred digits, otherwise the output two number of the sum.
Package Oracle.zibo.exam; Public classDemo { Public Static voidMain (string[] args) {//Client//TODO auto-generated Method StubSystem. out. println (Method ( A,8)); } Public StaticString Method (intAintb) { if((A*A+B*B) > -){ return "more than a few hundred"+ (A*A+B*B)/ -; }Else{ return "two number of the sum:"+ (A +C); } }
4. Implement string inversion, such as "hgy123" to get "132ygh"
Package Oracle.zibo.exam; Public classTestdemo { Public Static voidMain (string[] args) {method1 (); } Public Static voidmethod1 () {String str="hgy123"; for(intI=str.length ()-1; i>=0; i--){ CharC=Str.charat (i); System. out. Print (c); } }}
5. For any function x, returns the value of Y.
Package Oracle.zibo.exam;import Java.util.Scanner; Public classTest { Public Static voidMain (string[] args) {Fun3 (); } Public Static voidFun3 () {Scanner SC=NewScanner (System.inch); System. out. println ("Please enter the value of x:"); intx=Sc.nextint (); inty=0; if(x<=1) {y=x*x+x*2; System. out. println ("the value of y is:"+y); }Else if(x>1) {y=(int) Math.sqrt (x*x+1); Math.sqrt (); Take a number of root System. out. println ("the value of y is:"+y); } }}
6.5 inverse of array elements
5. Array elements in reverse order Public classTotal1 { Public Static voidMain (string[] args) {int[] arr={1,2,3,4,5}; intstart=0, end=arr.length-1; for(intj =0; J < Arr.length; J + +) { intTMP =Arr[start]; Arr[start]=Arr[end]; Arr[end]=tmp; Start++; End--; if(start>end) { Break; } } for(intj =0; J < Arr.length; J + +) {System. out. println (Arr[j]); } } }
7.4 Print 9*9 table with a for loop?
Public classTotal1 { Public Static voidMain (string[] args) { for(intI=0;i<9; i++){ for(intj=0; j<i+1; j + +) {System. out. Print ((j+1)+"x"+ (i+1)+"\ t"); } System. out. println (""); } }}
8.3 use for loop to print ABCDEFG ... xyz,26 uppercase and 26 lowercase letters
Public classTotal1 { Public Static voidMain (string[] args) {CharDa='A'; Charxiao='a'; for(intI=0;i< -; i++) {System. out. println ("uppercase letters are:"+da+"lowercase letters are:"+xiao);da++; Xiao++; //Note the difference between the output statement and the + + (at the back)//System.out.println ("Uppercase letters are:" +da+ "lowercase letters are:" +xiao); } }}
9.2 Output All daffodils number, the so-called Narcissus number refers to a number 3 digits, its per digit cubic and equals itself, such as 153 = 1*1*1 + * * 3 + 5*5* 5
Public classTotal1 { Public Static voidMain (string[] args) {intGe=0, shi=0, bai=0; for(intI= -;i< +; i++) {GE=i%Ten; Shi=i/Ten%Ten; Bai=i/ -; if((ge*ge*ge+shi*shi*shi+bai*bai*bai) = =i) {System. out. println (i); } } }}
Java Basics and Exercises