听课笔记(二)

1.三种基本流程结构:顺序结构、选择结构、循环结构。
2.选择结构:
if else(如果有两个else if的判断是一样的,只执行第一个,因为它条件满足就会跳出,不再执行下面的判断了)。
switch(表达式)(注意是表达式,表达式需是广义的整型(byte,short,int,long,char),不可以是String,boolean,可以是char)case (后面跟的是常量,不可以是变量,每句case后面需要加入break,如果没有,它会继续往下进行,而且是不匹配的,知道遇到break)。
3.循环结构:
while 循环:
while(表达式)(循环条件的要求:1.变量需要初始化。2.while主体需改变表达式的值,防止死循环)。
do while循环:
先执行一次循环,在进行判断,如果为真,继续执行,为假则不循环。
嵌套while循环:

先执行小循环,循环所有后,在执行大循环一次,在执行小循环所有。

4.==  用来比较地址,例如:String str1 = "abc",String str2 = "abc",此时str1和str2是相等的,因为它们都作为变量保存在栈里,现在如果用判断条件(str1=="abc"),这是不相等的,因为等号右边的"abc"并没有存入到内存,此时它只是一个内容,如果比较内容的话,用equals方法。现在如果改成 String str2 = new String("abc");此时str1和str2还是不等的,因为str1保存在栈内,而对象保存在堆内。

String a = "abc"; a变量保存在常量池,String b = new String("abc"); 此时b在常量池有一部分,堆内存也有一部分。

课堂练习:

package com.jereh;


import java.util.Scanner;


public class Condition {


/**
* @param args
*/
public static void main(String[] args) {


/*
* 1 烟台大学
* 2 文经学院
* 3 工商学院
*/ 

//学校代码
/*
int num=21;

if(num==1||num==2){

}else{
System.out.println("您没有权限进入");
}*/

// int num=1;
//  
// String str="zhangsan";
// char flag='A';
//
// switch(num){
//
// case 1:
// System.out.println("欢迎烟台大学的同学");
//
// case 2:
// System.out.println("欢迎文经学院的同学");
//
// case 3:
// System.out.println("工商学院");
//  
// default:
// System.out.println("没有");
//
// }
 




// char c='9';
// if(c>='0'&&c<='9'){
//
// System.out.println("数字");
//
// }else if(c>='a'&&c<='z'){
//
// System.out.println("小写字母");
//
// }else if(c>='A'&&c<='Z'){
//
// System.out.println("大写字母");
//
// }else{
// System.out.println("其他");
// }



// 会员卡

/*
//1 定义变量来存放会员信息
int cardNum;
String birth;
int score;
String cardPre="";
 
//2 输入会员信息
Scanner scaner=new Scanner(System.in);
System.out.println("请输入卡号:");
 
//1>录入卡号信息
cardNum=scaner.nextInt();
//2>校验卡号的合法性
if(cardNum>0&&cardNum<=9999){
//拼接前缀
if(cardNum<10){
cardPre="000" ;
}else if(cardNum<100){
cardPre="00" ;
}else if(cardNum<1000){
cardPre="0";

 
//输入生日
System.out.println("请输入生日(12/15):");
birth=scaner.next();
//输入积分
System.out.println("请输入积分");
score=scaner.nextInt();
//重置积分让积分大于0
score=score>0?score:0;
 
//打印结果
System.out.println("卡号:"+cardPre+cardNum +"\t生日:"+birth+"\t积分:"+score);
 
 
 
}else{
System.out.println("信息录入出错");
}

*/

// boolean condition=true;
//
// int index=1;
//
// while(index<=10){
// System.out.println(index +"*10="+index*10);
// index++;
//  
// }

// int i=10;
// do{
// System.out.println("hello jereh" + i);
// i++;
// } while(i<10);
//
/*Scanner scaner=new Scanner(System.in);
int num=0,result=8;

do{

System.out.println("请输入你猜的数字");
num=scaner.nextInt();

if(num>result){
System.out.println("输入的数字偏大了");
}else if (num<result){
System.out.println("输入的数字偏小了");
}else{
System.out.println("输入正确");
}

}while(num!=result);



int i=0;
while(i<=1){
int j=0;
while(j<=2){
System.out.println("小循环");
j++;
}
System.out.println("我是大循环");
i++;
}
*/

/*
//大循环,得出要计算阶乘数值
int index=1,sum=0;
while(index<=10){

           //小循环,计算每一个数的阶乘
int i=1,multi=1;
while(i<=index){
multi*=i;
i++;
}

sum+=multi;
index++;

}
 
System.out.println(sum);
*/


// ********     1   8
// ********    2   9   1
//  ********   3   10  1,2
//   ********  4   11  1,2,3


/*
int i=1;

//大循环打印行数
while(i<=4){
int j=1;
//小循环打印列数
while(j<=i+7){
if(j<=i-1){
System.out.print(" ");
}else{
System.out.print("*");
}
j++;
}
//换行
System.out.println();
i++;
}*/


/*
* 1
* 2 3
* 4 5 6
* 7 8 9 10
* 11 12 13 14 15
*/


/*
int i=1,lines=7,temp=1;
while(i<=lines){
int j=1;
while(j<=i){
System.out.print(temp+" ");
temp++;
j++;
}
 
System.out.println();
i++;
}
*/

//   *      1   3 (i+2)  2  3-i
//  ***     2   4        1  3-i
// ***** 3   5        0  3-i
//  ***    1   4 (5-i)  1
//   *    2   3        2

/* int j=1;
while(j<=3){
int i=1;
while(i<=j+2){
if(i<=3-j){
System.out.print(" ");
}else{
System.out.print("*");
}
i++;
}

System.out.println();
j++;
}*/

int num;
Scanner scaner=new Scanner(System.in);
while (true){
System.out.println("1 注册");
System.out.println("2 修改");
System.out.println("3 退出");
System.out.println("请选择。。。");
int right=scaner.nextInt();
 
if(right==1){
 
while(true){
System.out.println("请输入学号");
num=scaner.nextInt();
if(num<1000){
System.out.println("注册成功");
break;
}else{
System.out.println("输入的学号问题");
}
}
 
}else if(right==2){
 
 
}else if(right==3){
 
 
}else{
 
System.out.println("输入的权限代码有问题");
}
 
 
}



 
}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值