* First section
Eclipse operation, build Javaproject project (can be named directly in Chinese name) and build package with class (same name)->public static void Main (string[] args) {}
Multiple packages can be found in the same project
To enter a variable from the console: Run configurations
The reference import is written after the package, before the class:
Refer to several of the current contacts:
Import java.util.*; ------Scanner sc=new Scanner (system.in); int a=int new Int[4];a[i]=sc.nextint; it seems to be used for console input variables and use??
Import Javax.swing.JOptionPane; ------Referencing a message box for input and output
Import java.awt.graphics;//
Import javax.swing.*;//These two are pictures of the study, a face of the crazy
Import static java.lang.math.*;//apply mathematical function static call class name + Method Math.Abs ()
----SYSTEM.OUT.PRINTLN (ABS (-100)), equivalent to System.out.println (Math.Abs (-100));
Import java.math.biginteger;//for unlimited big data operations
* Section II
Language specification, the first thing that has not been very important is the name, here to mention
Class name capital starts with Findmax, constant names are all uppercase max-hight, function lowercase is increased getage
Second, when judging the character to be subtraction, the character type should be "enclosed".
The original is data type: Java only eight other types are used for reference. The "=" of the reference type here is judged by the same as ". Equals ()".
Enum type enum Size{small,medium,large}; Size S=size.small; Converts a string to an enumeration type Size t=size.valueof ("SMALL");//Traversal myenum value:MyEnum.values ();
A value of the same enumeration type refers to the same object.
Read-in user input at run time 1. Using Import Javax.swing.JOptionPane:
String Firstnumber =
Joptionpane.showinputdialog ("Enter:");
Number1 = Integer.parseint (Firstnumber);
Joptionpane.showmessagedialog (
NULL, "The number is" + number, "Results",
Joptionpane.plain_message);
System.exit (0);
2.imports java.util.*;
Scanner in=new Scanner (system.in);
System.out.print ("What is your name?");
String name=in. nextline ();//The difference here Nextint
System.out.println ("Hello," + name)
Force Data Conversion:
1. Integral type: int number = Integer.parseint (numberstring);
2.double:double number1 = double.parsedouble (Firstnumber);
* After class:
Random number generation verification code;
int intval = (int) (Math.random () * 26 + 97);//Generate an integer of type int of 97~122
result = result + (char) intval;//Intvalue cast to char after connecting to result
* Experiment:
palindrome number:
Guess number:
message box input output and perform subtraction operation:
* Section III
The defined function writes:
Permission +static+ return value type + method name (parameter list) {return}
How to use:
Class name + method or method name
Note that the function definition is usually added as static, otherwise it is done by initializing new and then invoking the
MyClass obj = new MyClass ();
Class MyClass {
Public fields
Public String information = "";
Data members are set to private
private int value;
The defined function is set to the public
public int GetValue () {
return value;
}
}
Use Math.random to generate random numbers, but there may be rules to find
Math.random (), generates a random decimal between the 0~1.
Math.random () *6, generates a random decimal between 0~5.
(int) (Math.random () *6), which takes a random number between the generated 0~5, forces the rounding, and ultimately the random integer between the 0~6
(int) (Math.random () *6) +1, generates a random number between 1~7.
Use seed time to generate irregular random numbers:
Random class import Java.util.Random;
Simple generation of 1~50 random numbers
Random r1 = new Random (50);//Generate 0~50
Use time as reference number
Random r4 = new Random (System.currenttimemillis ());
R1.nextint (); R1.nextboolean (); R1.nextgaussian (); r1.nextdouble ();//Generate type Data
Methods with variable parameters:
Variable parameter method This parameter can only be placed on the last side of the parameter list;
For loop enhanced for (double v:values), which is equivalent to removing each value in the values array to V, until the end
Methods to overload the method:
(1) The method name is the same;
(2) different parameter types, different number of parameters, or different order of parameter types
Note: The return value of the method is not evaluated as a method overload
Handle Unlimited Data subtraction:
BigInteger class reference Import Java.math.BigInteger;
Add A.add (b); Similarly, subtract subtract (); multiply multiply (); divide divide (); seek remainder remainder ();
Some methods of the math function:
Http://zhidao.baidu.com/link?url=PnME6Xgb9xmX3mKMNijn-p4pKMaTYNXNzPSQJ_oN0h4xTx1zEURwErzaXCz-0xa8jEwI_qrHOIHMTknV3fdlIa
Two-dimensional arrays: a lot of choices.
int b[][];//Definition
B=new int[n][n];//allocation space
Short[][] Numfour=new short[5][8];//define and allocate space
Int[][] numseven=new int[][]{{10,20,30},{40,50},{60}};//define an irregular 2-dimensional array and assign an initial value
Int[][] numeight={{100,200,300,400},{500,600,700,800},{900,1000,1100,1200,1300}};//defines an irregular 2-dimensional array and assigns an initial value;
......
Recursion and recursion:
Write Yang Hui triangle job found recursion and recursion look wrong! And then discover it further! Hold the Grass! I don't know that either! I don't know! No, I don't know! Ah!
Recursion is as follows:
int sum=0;
for (int i=0;i<n;i++) {
Sum=sum+i;
}//from small to large
Recursion is as follows:
public static int QH (int a) {
if (a==0) return 0;
if (a==1) return 1;
Else
Return A+QH (a--);
}//from big to small
String problems:
The first problem arises when judging the palindrome number.
String X=SC1. Nextline ();//Note Oh, int a=sc.nextint (); int is not the same as line!
int i=s.length ();//string for length, with its own function
Char[] Ch1=s.tochararray ();//Convert a string type to a char type, why convert it? Because Char has an array string no Yes
public static Boolean hwspd (String s) {
int I=s.length ();
Char[] Ch1=s.tochararray ();//Convert to String
if (i<1) return false;//<1
else if (i==1) return true;//=1
else if (S.charat (0)!=s.charat (i-1)) {
return false;}
Return hwspd (s.substring (0,i-1));
}
Str.substring (3,7) return string 1th to 3rd substring in STR does not include the third character
String str= "1234567";
Str=str.substring (1, 3);
System.out.println (str);
Output is 23
Three-time Java Lab finishing report: