A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

徐俊杰

初级黑马

  • 黑马币:22

  • 帖子:6

  • 精华:0

© 徐俊杰 初级黑马   /  2018-3-25 14:21  /  889 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

人的记忆力是有限的,需要不断的重复去记忆理解才能在脑海中留下深刻印象,当然有人天赋异禀的人除外.因此每天对学习的东西进行总结是有必要的.每个人对新知识的理解和接受能力是一样的,所以每个人总结的时候侧重点是一样的,接下来我分享下我总结的笔记,由于篇幅有限,就发下前4天的笔记.
第一天
1.dos的打开方式和命令
①打开方式:win+R+cmd+enter
②dos命令:   cd退回上一级目录
      cd\退回根目录
      cls清屏
      dir列出当前目录下的文件以及文件夹
2.Java语言的特性:开源和跨平台
3.JDK的下载和安装y以及环境变量的配置(重点):JAVA_HOME的配置:路径为jdk的按照目录
                Path:%JAVA_HOME%/bin;
4.输出HelloWorld:
class Test01 {
public static void main(String[] args) {
System.out.println("HelloWorld");
}
}
5.Java书写格式(重点,做到见名知意)
①括号类需成对出现
②左大括号前要空一格,第二行要缩进一个Tab
③方法之间以及程序块之间需要空一行
④并排语句之间要加空格,例如for语句.(if算吗?)
⑤运算符两侧需要家空格
⑥包:所有字母小写,最好是域名倒过来
⑦类或接口:大驼峰
⑧方法或者变量:小驼峰
⑨常量:所有字母大写,多个单词时,单词之间用下划线区分每个单词(JAVA_HOME)
⑩标识符(类,方法,变量的名字):a.英文大小写字母,数字字符,$和_;
      b.不能使用关键词,不能使用数字开头
6.数据类型以及变量的定义格式
数据类型:a.基本数据类型:String,char,byte,short,int,long(值后面需要加L),float,double,boolean
数据类型 变量名 = 变量值;
例:int num = 10;  String name = "张三" ; char sex = "男",boolean a = true;
byte占一个字节,取值范围为-128~127
7.变量注意事项以及数据类型转换
隐式转换:默认转换规则,先将小的数据类型提升为大的数据类型在进行运算
强制转换:格式   不需要转换的变量 = (需要转换的数据类型)(需要转换的变量)
例: int a = 10;
byte b = 20;
b = (byte)(a + b);
变量注意事项:同一区域(方法)不能使用相同的变量名
局部变量没有默认值,需要在使用之前赋值;成员变量有默认值

第二天
1.eclipse的安装和使用
2..算术运算符:①+(加法运算,正号,字符串的拼接),-,*,/(整数相除只能得到整数),%(取余)
②++,--:单独使用: ++(--)在前后无区别//将(a++)或(++a)看成一个整体
参与运算: ++(--)在前面,先自增(自减)再使用,//++a自身+1,整体+1
   ++(--)在后面.先使用在自增  //a++,自身不变,整体+1
例:byte = 10;
b++;//相当于 b = (byte)(b+1);
b = b + 1;//这句会报错,因为1是int类型的,b是byte类型的,需要进行强制转换才可以
3.赋值运算符:+=,-=,*=,/=,%-=
例:sum = sum + i;//简化sum += i;两式所表达的意思一样
4.关系运算符:==,>,>=,<,<=,!=用于判断等式两边,结果是boolean类型
5.逻辑运算符:&(and),|(or),^
①&(and): 两边为真才为真,有false则为false
②|(or): 有true则为true
③^:两边相同为false,两边不同为true; 一个
一个数异或另一个数两次,其结果等于这个数的本身
例: 4 ^ 5 ^ 5 = 4
将a和b的值对换(不借助第三方变量)
class Test {
public static void main(String[] args) {
int a = 5;
int b = 4;
a = a ^ b;
b = a ^ b;//由于a = a^ b,因此b = a ^ b ^ b = 5 ^ 4 ^ 4 = 5;
a = a ^ b;//a = a ^ a ^ b = 4 ^ 4 ^ 5 = 4;
System.out.println(a+","+b);
}
}

④&&(短路于): 左边为false,右边不执行
    ||(短路非): 左边为true,右边不执行


6.三元运算符
关系表达式? 表达式1 : 表达式2;
/*
比较a , b ,c三个值的大小,打印出最大数
*/
public class Test {
int a = 10;
int b = 20;
int c = 30;
int temp = (a > b)? a : b;
int max = (temp > c)? temp : c;
System.out.println(max);
}
7.键盘录入的步骤和使用
①导包 : imoort java.util.Scanner;
②创建键盘录入对象 : Scanner sc = new Scanner(System.in);
③接收数据 : int i = sc.nextInt();
import java.util.Scanner;
public class Test {
Scanner sc = new Scanner();
System.out.println("请输入第一个数据");
int a = sc.nextInt();//怎么输入一个数组呢?
System.out.println("请输入第二个数据");
int b = sc.nextInt();
System.out.println("请输入第三个数据");
int c = sc.nextInt();
int temp = (a > b)? a : b;
int max = (temp > c)? temp: c;
System.out.println("max");
}

第三天
一、控制条件语句
1.break;结束循环
2.continue;结束本次循环,继续下次循环
3.return;结束方法,不是结束循环
二、选择结构
1.if的三种格式: ①if (a > b) {//条件表达式
System.out.println("判断");//语句体,条件表达式结果为true,才会执行语句体
}
   ②if(a > b) {
a = c;
}else {
b = c;
}
   ③if(a > b) {
a = c;
}else if {
b = c;
}else {
System.out.println("我不知道你在说什么");
}
    ④if的嵌套
if(a > b) {
if(a > c) {
System.out.println("最大值为"+a);
}else {
System.out.println("最大值为"+c);
}
}else {//a < = b;
if(b > c) {
System.out.println("最大值为"+b);
}else {
System.out.println("最大值为"+c);
}
}
2.switch:   switch(表达式) {//表达式可为string类型,也可为整数类型
       case 值1:
语句体1;
break;
case 值2:
语句体2;
break;
case 值3:
语句体3;
break;
...
default:
语句体n+1;
break;
三、循环结构
1.for循环 :
class Test1 {
public static void main(String[] args) {
for(int i = 1;i < 10;i++){
System.out.println(i);
}
}
}

2.while循环
class Test2 {
public static void main(String[] args) {
int i = 1;
while(i < 10) {
System.out.println(i);
i++;
}
}
}

3.do...while循环
class Test3 {
public static void main(String[] args) {
int i = 1;//初始化语句
do {
System.out.println(i);//循环体语句
i++;//控制条件语句
}while(i < 10) ;//判断条件语句
}
}
4.for,while,do...while的区别
do...while不管是否符合条件都会先运行循环体语句,for和while是先判断是否符合条件,符合条件的情况下才会运行循环体语句
for循环在循环结束后就不能使用循环的变量了,而while循环仍然保留循环的变量的值
例:
class Test1 {
public static void main(String[] args) {
for(int i = 1;i < 10;i++){
System.out.println(i);
}

System.out.println(i);//这里会报错,因为变量i已经被释放了,不能被调用
}
}

class Test2 {
public static void main(String[] args) {
int i = 1;
while(i < 10) {
System.out.println(i);
i++;
}

System.out.println(i);//这里的i仍然有值,i = 10;
}
}
5.求三位数的水仙花数
class Test4 {
public static void main(String[] args) {
for(int i = 100; i <= 1000;i++ ) {
int uti = i % 10;
int dec = i / 10 % 10;
int hun = i / 100;
if(uti * uti * uti + dec * dec * dec + hun * hun * hun == i) {
System.out.println(i);
}
}
}
}

第四天
一.Random的使用
    使用步骤: 1.导包:import java.util.Random
      2.创建对象 : Random r = new Random();
      3.获取数据的范围 : int number  = r.nextInt(10);
获取数的范围:[0,10)包括0,不包括10
二、数组
1.动态初始化: int[] arr = new int [5];
数据类型 数组名 = new 数据类型[数组长度];
2.静态初始化: int[] arr = new int []{1,2,3,4,5};
  int[] arr = new int{1,2,3,4,5};
3.数组反转遍历
class Test{
public static void main(String[] args) {
int[] arr = new int[]{1,2,8,5,7,9,3,4,5};
for(int i = 0;i < arr.length/2;i++){
int temp = arr[i];
arr[i] = arr[arr.length-1-i];
arr[arr.length-1-i] = temp;
}
for(int i = 0;i < arr.length;i++ ) {
System.out.println(arr[i]);
}
}
}
4.空指针异常NullPointerException
数组的地址值已经被null了
   数组索引越界异常IndexOutOfBoundsException
,                        数组的这个索引不存在
三、二维数组
1.二维数组的格式
int[][] arr = new int[i][j];
int [][] arr = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
2.二维数组的遍历
public class Test {
public static void main(String[] args) {
int[][] arr = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
for(int i = 0; i < arr.length; i++) {
System.out.print("{");
for(int j = 0; j < arr[i].length; j++) {
if(j == arr[i].length-1) {
System.out.println(arr[i][j] + "}");
}else {
System.out.print(arr[i][j] + ",");
}
}       
}
}
}
3.二维数组的反转
public class Test {
public static void main(String[] args) {
}

public static void reverseArray(int[][] arr) {
for(int i = 0; i < arr.length; i++) {
for(int j = 0; j <= arr[i].length / 2; j++) {
methon(arr,i,j);

if(j == arr[i].length / 2 && i <= arr.length /2 ) {
methon(arr,i,j);
}
}
}
}

public static void methon(int[][] arr, int i ,int j) {
int temp = arr[i][j];
arr[i][j] = arr[arr.length - 1- i][arr[i].length - j -1];
arr[arr.length - i -1][arr[i].length - j -1] = temp;
}

public static void print(int[][] arr) {
for(int i = 0; i < arr.length; i++) {
System.out.print("[");
for(int j = 0; j < arr[i].length; j++) {
if(j == arr[i].length - 1) {
System.out.println(arr[i][j] + "]");
}else {
System.out.print(arr[i][j] + ",");
}
}
}
}
}

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马