2017/12/24 java基础

1、classpath 是为了保存.class文件所在的位置;提供运行java命令时的第一位置,如果加上了“.”,会优先在当前目录查询;“.”放在;后面则
优先查询设定的目录。没有“;”,不再其他目录进项查询;
2、转义字符好像没什么作用;
3、二进制转换除以2,转回来要每个乘当前位数减一并相加;110 0*2(0)+1*2(1)+1*2(2)=6;
4、基本数据类型
字节byte 8
字符型char 16
短整型short 16
整型int 32
单精度浮点型float 32
长整型long 64
双精度浮点型double 64
布尔类型Boolean 1或者4

5、负数在计算机中以补码的形式存在;
取反+1;
6、数据类型转换时的大小指的是所占内存空间的大小;
7、算术表达式,逻辑表达式计算时:所有的byte型、short型和char的值将被提升到int型。
8、位操作符用来操作整数基本数据类型中的单个比特(bit),就是二进制,按位操作符会对两个参数中对应的位(bit)执行布尔运算,最终生成一个结果。
9、位移运算符进行的二进制方面的运算;
10、匿名对象没有对应的名字,多用来作为实参调用方法;
11、封装便是用private修饰变量,再设置相应的set和get方法来对变量进行传值和调用;
12、构造方法用来在创建对象的时候,给对象的属性赋值;
13、构造代码块作用:给所有的对象进行统一的初始化。
14、switch暂时不支持String类型的变量!
15、syso加alt+/可以直接输出System.out.println();
16、a调用一个b函数,传入b函数的变量的值,不会在a函数中发生改变;因为变量的地址不是一个;想要使用b函数改变后的值,可以返回值,也可以传入数组;

幸运号码抽奖:

package day01;

import java.util.Scanner;

public class Exercises5 {
    //主界面
public static void main(String[] args) {
    Boolean judge=true;
    String [] user=new String[3];
    while(judge){
    view1(); //界面
    Scanner input=new Scanner(System.in);
    int select=input.nextInt();
    select(judge, user, select);
 }

}
//选择
public static void select(Boolean judge, String[] user, int select) {
        switch(select){
        case 1:
        System.out.println("奖客富翁系统->注册");
        register(user,judge);// 注册
        break;
        case 2:
        System.out.println("奖客富翁系统->登录");
        login(user,judge);  //登录
        break;
        case 3:
        System.out.println("奖客富翁系统->抽奖");
        lucky(user, judge);
        break;
        default:
            System.out.println("您的输入有误!");
        }
    }
//显示
public static void view1() {
    for(int i=0;i<6;i++){
        System.out.print("*");
    }
    System.out.print("欢迎进入奖客大富翁系统");
    for(int i=0;i<6;i++){
        System.out.print("*");
    }
    System.out.println("");
    for(int i=0;i<9;i++){
        System.out.print(" ");
    }
    System.out.println("1注册");
    for(int i=0;i<9;i++){
        System.out.print(" ");
    }
    System.out.println("2登录");
    for(int i=0;i<9;i++){
        System.out.print(" ");
    }
    System.out.println("3抽奖");
    for(int i=0;i<27;i++){
        System.out.print("*");
    }
    System.out.println("");
    System.out.print("请选择菜单:");
}
//继续模块
public static void countinue(boolean judge){
    Boolean judge2=true;
    while(judge2){
    System.out.print("继续吗?(y/n):");
    Scanner input2=new Scanner(System.in);
    String command=input2.next();
    if("y".equals(command))
    {
        judge2=false;
    }
    else if("n".equals(command)){
        judge=false;
        judge2=false;
    }
}
}
//注册模块
public static void register(String[] user,boolean judge){
    Scanner input =new Scanner(System.in);
    System.out.print("输入用户名:");
    user[0]=input.next();
    System.out.print("输入密码:");
    user[1]=input.next();
    int id=(int)((Math.random()*9+1)*1000);
    user[2]=Integer.toString(id);
    System.out.println(user[2]);
    System.out.println("注册成功!请记好您的会员卡号!");
    System.out.println("用户名 	密码	卡号 ");
    System.out.println(user[0]+"	"+user[1]+"	"+user[2]+"	");
    countinue(judge); //继续模块
}
//登录模块
public static void login(String[]user,boolean judge){
    for(int i=0;i<3;i++){
    Scanner input =new Scanner(System.in);
    System.out.print("请输入用户名:");
    String username1=input.next();
    System.out.print("请输入密码:");
    String password1=input.next();
    System.out.print("请输入会员卡号:");
    String id1=input.next();
    if(user[0].equals(username1)&&user[1].equals(password1)&&user[2].equals(id1)){
        System.out.println("登陆成功!");
        i=i+3;
        judge=true;
    }
    else{
        judge=false;
    }
    }
    countinue(judge); //继续模块
}
//幸运抽奖
public static void lucky(String[] user,boolean judge){
    int id1=(int)((Math.random()*9+1)*1000);
    int id2=(int)((Math.random()*9+1)*1000);
    int id3=(int)((Math.random()*9+1)*1000);
    int id4=(int)((Math.random()*9+1)*1000);
    int id5=(int)((Math.random()*9+1)*1000);
    int num=Integer.parseInt(user[2]);
    if(num==id1||num==id2||num==id3||num==id4||num==id5){
        System.out.println("抽奖成功!");
    }else{
        System.out.println("谢谢光临!");
    }
    countinue(judge); //继续模块
}

}
原文地址:https://www.cnblogs.com/loong996/p/8099431.html