第一个例子:
public class Example2_1{
public static void main (String args[]){
char chl = 'w',ch2 = '好';
int pl = 32831,p2 = 30452;
System.out.println;
System.out.println;
System.out.println;
System.out.println;
System.out.println;
}
}
第二个例子 :
public class Example2_2{
public static void main (String args[]){
byte b = 22;
int n = 129;
fioat f =123456.6789f ;
double d = 123456789.123456789;
System.out.println;
System.out.println;
System.out.println;
System.out.println;
b = (byte)n;
f = (float)d;
System.out.println;
System.out.println;
}
}
第三个例子:
import java, util.Scanner;
public class Example2_3 {
public static void main (String args[ ]){
System.out.println;
Scanmer reader = new Scanner;
double sum = 0;
int m = 0;
while(reader.hasNextDouble()){
double x = reader.nextDouble();
m = m+1;
sum = sum + x;
}
System.out.println;
System.out.println;
}
}
第四个例子:
public class Example2_4 {
pubilc static void main(String args[]){
int a[] = {1,2,3,4};
int b[] = {100,200,300};
System.out.println;
System.out.println;
System.out.println;
System.out.println;
System.out.println;
a = b;
System.out.println;
System.out.println;
System.out.println;
System.out.println;
System.out.println;
}
}
第五个例子
:
import java.util.Arrays;
public class Example2_5{
public static void main(String args[]){
char [] a = {'a','b','c','d','e','f',},
b = {'1','2','3','4','5','6',};
int [] c ={1,2,3,4,5,6},
d = {10,20,30,40,50,60};
System.arraycopy(a,0,b,0,a.length);
System.arraycopy(c,2,d,2,c.length - 3);
System.out.println("数组a的各个元素中的值:");
System.out.println(Arrays.toString(a));
System.out.println("数组b的各个元素中的值:");
System.out.println(Arrays.toString(b));
System.out.println("数组c的各个元素中的值:");
System.out.println(Arrays.toString(c));
System.out.println("数组d的各个元素中的值:");
System.out.println(Arrays.toString(d));
}
}
第六个例子:
import java.util.*;
pubilc class Example2_6 {
pubilc static void main (String args[]){
int [] a = {10,20,30,40,50,60},b,c,d;
b = Arrays.copy0f(a,10)
System.out.println;
System.out.println(Arrays.toString(a));
System.out.println;
System.out.println(Arrays.toString(b));
c = Arrays.copyOfRange(a,3,5);
System.out.println;
System.out.println(Arrays.toString(c));
d = Arrays.copy0fRange(a,3,9):
System.out.println;
System.out.println(Arrays.toString(d));
}
}
第七个例子:
import java.util.*;
public class Example2_7{
public static vod main(String args[]){
int[]a={12,34,9,23,45,6,45,90,123,19,34};
Arrays.sort(a);
System.out.println(Arrays.toString(a));
int number=45;
int index=Arrays.binarySearch(a,number);
if(index>=0){
System.out.println(number+"和数组中索引为“+index+"的元素值相同”);
}
else{
System.out.println(number+"不与数组中的任何元素值相同");
}
}
}
第八个例子:
import java.util.Scanner;
enum Season{
春季,夏季,秋季,冬季
}
public class Example2_8{
public static void main(String args[]){
Season x = null;
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
if(n == 1)
x = Season.春季;
else if(n == 2)
x = Season.夏季;
else if(n == 3)
x = Season.秋季;
else if(n ==4)
x = Season.冬季;
System.out.println("现在是"+ x);
}
}
第九个例子:
public class Example2_9{
public static void main(String args[]){
Weekday x=Weekday.星期日;
if(x==Weekday.星期日){
System.out.println(x);
System.out.println("今天我休息");
}
}
}