7月13日总结

时间:2022-04-18 11:47:52

程序编写格式:TAB和shift+TAB(取消缩进) ;运算符前后加空格(for语句中的可不加空);各种括号要成对的敲;结尾大括号要和自身开头那句对齐。
UltraEdit使用技巧:新建文件后就保存(F12),否则无提示语句也无颜色。
标示符:可以起名字的东西
关键字:特殊用途的字符序列
运算符:递增的表示i++ ,i+=1
数据类型:byte,short,char在运算中自动转换成int类型;强制转换符f,L,(float),(long),(byte)
JAVA基本数据类型:局部变量,成员变量
if.. else语句
练习程序:
public class Test{
 public static void main(String arg[]){
  System.out.println(f(40));
 }
 public static int f(int n){
  if(n == 1 || n == 2){
      return 1;
     }else{
      return f(n - 1) + f(n - 2);
  }
 }
}
 for循环语句
练习程序:
public class TestOdd {
 public static void main(String args[]){
  long result = 0;
  for (int i=1; i<=99; i+=2){
   result += i;
  }
  System.out.println("result=" + result);
 }
}
while循环语句do..while循环语句(do..while后有分号)
练习程序:
public class TestWhile {
 public static void main(String[] args) {
  int i = 0;
  while(i < 10) {
   System.out.print (i);
   i++;
  }
  
  i = 0;
  do {
   System.out.println(i);
   i++;
  } while(i < 10);
 }
}
条件语句switch:防止case穿透,需要用break
练习程序:
public class TestSwitch {
 public static void main(String[] args) {
  int i = 9; 
  switch(i) {
   case 8 :
    System.out.println("A");
    break;
   case 3 :
    System.out.println("B");
    break;
   case 2 :
    System.out.println("C");
    break;
   case 9 :
    System.out.println("D");
    break;
   default:
    System.out.println("error");
  }
 } 
}
方法: 返回值类型必须写void,传递给方法的形参和实参的类型必须一样
变量的作用域:只在打括号内有意义。