zoukankan      html  css  js  c++  java
  • 201403java学习笔记

    主函数结构:

    public class Atm_Demo{

    public static void main(String[] args){

    //执行语句;

    }

    }

    java的数据类型:

    java数据类型分为两种:

    基础数据类型和引用数据类型。其中基本数据类型包括:(数据型)byte,short,int,float,double,long、(字符型)char、(布尔型)boolean;引用数据类型包括String,(类)class、(接口)interface、(数组)Array,Map也只能算引用数据类型了。

    java基础数据类型:

    数据类型   大小   范围   默认值

    byte(字节型)  8   -128~127   0

    short(短整型) 16                 0

    int(整型)       32                   0

    long(长整型) 64                  0

    float(浮点型) 32                   0.0f

    double(双精度)64      0.0d

    char(字符型)   16                'u0000 '

    boolean(布尔型) 1  true/false false

    判断及循环语句结构:

     

    I.判断语句:

    1.if语句:

    A.If(){

    //执行语句;

    }

    B.if(){

    //执行语句;

    }else{

    //执行语句;

    }

    C.if(){

    //执行语句;

    }else if{

    //执行语句;

    }

    ……

    else{

    //执行语句;

    }

    2.switch语句:

     switch(表达式){

    case 常量表达式1:语句1;

    case  常量表达式2:语句2;

    ……

    default:语句;

    }

    II.循环语句:

    1.for循环语句:

    for(循环变量初始值;循环条件;循环变量增值){

    statement;

    }

    2.while循环:

    while(条件){

    //循环体;

    }

     

    3.do while循环:

     

    do{

     

    //循环体;

     

    }while(条件)

     

    III.各循环语句的区别:

     

    1.for与while循环的区别:

     

    for循环多用于知道循环次数的情况下;

     

    while循环多用于不知道循环次数的情况下,通过某些条件判断控制循环次数;

     

    2.while循环与do while循环的区别:

     

    do while先执行循环体,再判断条件,如果条件满足,继续执行,不满足,退出循环;

     

    while循环先判断条件,满足就执行循环体,不满足退出;

     

     

    常用语句:

     

    1、获取捕捉到的信息并赋值给变量:

     

    Import java.util.Scanner;

     

    System.out.println("请输入月份:");

     

    Scanner sc = new Scanner(System.in);

     

    Int类型的接收:

     

    Int month = sc.nextInt();

     

    Double类型的接受:

    double d = sc.nextDouble();

     

    String类型的接收:

     

    String month = sc.next();

     

    例:

    import java.util.Scanner;

     

    public class Test20140814 {

           public static void main(String[] args){

                  System.out.println("欢迎使用果果牌银行存取系统");

                  Scanner input=new Scanner(System.in);

                  int pwd=input.nextInt();// 开户123456

                  boolean f=pwd==123456;

                  System.out.println("你输入的密码正确吗?"+f);

                  if(pwd==123456){

                           System.out.println("恭喜你,可以取钱了");

                  }

           }

    }

     

    2、用在判断语句中的各类型值的比较:

     

    String类型的比较:

     

    String str1 = sc.next();

     

    If(str1.toUpperCase().equals("A"))

     

    int类型的比较:

     

    If(month==1)

     

    3、获取字符串中的某一个字符:

    public class Test20140818 {
     public static void main(String[] args){
      String s = "abcde";
      char ss = s.charAt(3);  //(字符在字符串中位置)
      System.out.print(ss);   //d
     }
    }

    4、随机器:

    import java.util.Random;

    import java.util.Scanner;

     

    public class Test20140821 {

           public static void main(String[] args){

                  /*接收值Scanner:

                  Scanner input=new Scanner(System.in);

                  int quantity=input.nextInt();

                  */

                  //随即器,随机产生整数Random:

                  Random r=new Random();

                  int month =r.nextInt(12);//0~11

                  month=month+1;//1~12

                  if(month>0&&month<4){

                         System.out.print("第一季度");

                  }else if(month>3&&month<7){

                         System.out.print("第二季度");

                  }else if(month>6&&month<10){

                         System.out.print("第三季度");

                  }else{

                         System.out.print("第四季度");

                  }

           }

       

  • 相关阅读:
    Unity The Method Signature Matching Rule
    Unity The Property Matching Rule
    Unity The Type Matching Rule
    Unity The Custom Attribute Matching Rule
    Unity The Member Name Matching Rule
    Unity No Policies
    Unity The Return Type Matching Rule
    Unity The Parameter Type Matching Rule
    Unity The Namespace Matching Rule
    关于TSQL递归查询的(转)
  • 原文地址:https://www.cnblogs.com/lisu/p/3869702.html
Copyright © 2011-2022 走看看