This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Pandy | |
* @date 2018/4/22 11:01 | |
*/ | |
import java.util.*; | |
public class ArrayNew { | |
public static void main(String[] args) { | |
int[] a;//也可以在数组定义的同时进行初始化 int[]a = new int [rand.nextInt(20)] | |
Random rand = new Random(47);//创建一个rand对象 | |
a = new int[rand.nextInt(20)];//rand.nextint方法会随机生成一个0到输入参数之间的一个值 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Pandy | |
* @date 2018/4/21 18:41 | |
*/ | |
public class Flower { | |
int petalCount = 0; | |
String s = "initial value"; | |
Flower(int petals){ | |
petalCount = petals; | |
System.out.println("Constructed w/ int arg only,petalCount = "+ petalCount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Queen { | |
private final int size;//棋盘的大小 | |
private int[] location;//皇后在棋盘上每行上的列的位置 | |
private int[] colsOccupied;//皇后在棋盘上占据的列 | |
private int[] cross1Occupied;//皇后在棋盘上占据的正对角线 | |
private int[] cross2Occupied;//皇后在棋盘上占据的反对角线 | |
private static int count;//解决方案的个数 | |
private static final int STATUS_OCCUPIED=1;//占领状态 | |
private static final int STATUS_OCCUPY_CANCELED = 0;//未占领状态 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Array2Demo { | |
public static void main(String args[]) { | |
//int[] arr = new int[3];//一维数组 | |
//int[][] arr = new int[3][4]; //定义了名称为arr的二维数组 | |
//System.out.println(arr); | |
// int [][] arr =new int[3][];//数组没有初始化 默认是null | |
// arr[0] = new int[3];//二维数组中的第一个引用指向了一个小的数组 | |
// arr[1] = new int[1]; | |
// arr[2] = new int[2]; | |
// System.out.println(arr.length);//打印的是二维数组的长度 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ArrayTest2 { | |
//排序函数体 | |
public static void selectSort(int[] arr){ | |
for (int x =0;x<arr.length-1;x++){ | |
for (int y = x+1;y<arr.length;y++){ | |
if (arr[x]>arr[y]){ | |
int temp = arr[x]; | |
arr[x] = arr[y]; | |
arr[y] = temp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BreakContinueDemo { | |
public static void main(String[] args){ | |
/* | |
* breakt跳出 | |
* break作用的范围,要么是switch语句,要么是循环语句 | |
* 当break语句存在时,下面不要定义其他语句,因为执行不到 | |
*如果出现循环嵌套,可以通过标号跳出循环 | |
* 跳出指定的标签,就意味着只能在循环区间 | |
* 在区间外面,则break语句失效!*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MultiplicationTable { | |
public static void main(String[] args){ | |
for (int i = 1;i<=9;i++){ | |
for (int j =1;j<=i;j++ ){ | |
System.out.print(j+"x"+i+"="+i*j+"\t"); | |
} | |
System.out.println(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ForForTest2 { | |
public static void main(String[] args){ | |
for (int x = 1;x<=5;x++){ | |
for (int y = 1;y<x;y++){ | |
System.out.print("-"); | |
} | |
for (int z = x;z<=5;z++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Sample2 { | |
static boolean booleanVar; | |
static String stringVar; | |
Doll dollVar; | |
int intVar; | |
char charVar='*'; | |
//各种类型的默认值 | |
public static void main(String[] args){ | |
Sample2 obj = new Sample2(); | |
System.out.println(booleanVar); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ParamTester { | |
public int memberVariable = 0; | |
public static void main(String[] args){ | |
//声明并初始化4个局部变量 | |
int param1 = 0; | |
ParamTester param2 = new ParamTester(); | |
ParamTester param3 = new ParamTester(); | |
int[] param4 = {0}; |