Java Learning 031, Java interview some questions
First, what is a variable
Variables are data that is mutable during the execution of a program. A variable in a class is a property that is used to represent tiredness, and in the course of programming, you can modify the value of a variable. Variables are usually variable, that is, the values change
Ii. what is a function
1, to achieve a specific function of a section of code 2, can be reused multiple times.
Three, what is an array
An array is a collection of data used to store the same data type, and the data in the array can be applied using a common name. Arrays can store any type of data, including raw data types and objects.
2. The skills of circular reading
The outer loop is done once, the inner loop is done again
3, 1234 change to 4321
int right;
int value = 1234;
while (value!=0) {
right=value%10;
System.out.print (right);
VALUE=VALUE/10;
}
4. Arrays
Declaration of an array
Int[] A;
int a[];
Spatial allocation of arrays
A = new int[5];
Int[] A;
A = new int[5];
Int[] A = new int[5];
Initialization of the array
One is: First, declare the value in the assignment
int [] a=new int[2];
A[0]=1;
a[1]=2;
The other is: direct declaration assignment
int [] a={1,2};
Attention:
L The memory space created by the array can only store the same type of data
The allocated memory space of the array is contiguous
The memory space allocated by the L array is not extensible
If the output of an int array is not error output 0
Output NULL if a string array is out of bounds output error
The others are as follows:
Expansion of Arrays
One, the first way
Int[] a={1,2,3};
Int[] B=new int[a.length*2];
for (int i=0;i<a.length;i++) {
B[i]=a[i];
}
A=b;
Two, the second way system.arraycopy ()
Int[] a={1,2,3};
Int[] B=new int[a.length*2];
System.arraycopy (a,0,b,0,a.length);
A refers to the original array, 0 primitive array subscript, b destination array, 0 destination array subscript, a.length the length of the original array
A=b;
Three, the Third Way of Java.util.Arrays.copyOf ()
Int[] a={1,2,3};
Int[] b=java.util.arrays.copyof (a,a.length*2); A refers to the original array
A=b;
Two-dimensional arrays
Declare a two-dimensional array:
int [] [] A;
To create a two-dimensional array:
Int[][] A = new int[2][3]
Traversal of two-dimensional arrays:
A[i].length: The length of the first row array
A two-dimensional array is an array of nested one-dimensional arrays
Array sorting
The sort function is arranged in ascending order, you can sort all the arrays, or you can sort the elements within a specified range.
Arrays.sort (array);
Or
Arrays.sort (array, start subscript, end subscript);
5, how to create a two-dimensional array, 1th row 3 column 2nd row 2 column
A[0]=new int[3];//declares a one-dimensional array into the first row of a two-dimensional array
A[1]=new int[2];
a[0][1]=1;//1th Row 2nd Column Assignment
6. Some Java programming examples
First, if a number equals the sum of all its factors, we call this number "finish", for example 6 of the factor is 6=1+2+3 6 is a complete number. Please program to print out all the numbers within 1000
/**
*
*/
Package com.oracle.it.day3;
/**
* @author Admin
* @version 1.0
* @date2015 Year July 24
* Print all the finished numbers within 1000
*/
public class Work1 {
public static void Main (string[] args) {
for (int num=1;num<=1000;num++) {
Wanshu (num);
}
}
public static void Wanshu (int num) {
int sum=0;
for (int i=1;i<=num/2+1;i++) {
if (num%i==0)
Sum=sum+i;
}
if (sum==num)
System.out.println (num+ "is the end number");
}
}
Second, output 99 multiplication table
Three, programmed output all three daffodils number Narcissus number: The number of cubic number of the sum equal to the numbers itself for example: 153 1*1*1+5*5*5+3*3*3=153,153 is a three-bit narcissus number.
Java Learning 03