字符串:String(不是基础数据类型,引用字符类型)
字符串必须使用" ", +:连接字符串,如果其他的数据类型+" "就变成了字符串
三大结构:顺序 选择 循环
选择:
if(else)switch (case) (break)(default)
if:多用于范围选择 switch多个单值匹配。
java中的switch可以是整数,字符,不能支持字符串
循环:
while(){ } do{}while() for0(;;){}
while和dowhile 区别为:dowhile至少会执行一次。
边界值问:只要限定范围就需要注意边界值
while和if的区别:结束的地方不一致,while在条件结束,当满足条件执行完以后为需要进行条件判断就用while。
/**
字符串:String(不是基础数据类型,引用数据类)字符串必须使用""
+:链接字符串,如果其他的数据类型+""就变成了字符串
三目,
++a;a+b,
*/
class JavaDemo6
{
public static void main(String[] args)
{
String name = "haoren";
String name1 = new String("huairen");
int temp = 3;
System.out.println(name);
System.out.println(name1);
System.out.println(temp+""+1);
int score = 65;
System.out.println(score>=80?"优秀":"及格");//条件表达式(三目运算)
}
}
/**
三大结构:
顺序
选择:
if else switch
if多用于范围选择,switch多个单值匹配。java中的switch可以是整数、字符(java中char会自动转换了int)
循环:while(){} do{}while() for(;;){}
*/
class JavaDemo7
{
public static void main(String[] args)
{
//选择
if(2>1){
System.out.println("成立");
}else{
System.out.println("不成立");
}
/*
if(){
if(){
}
}
if(){
}else if(){
}
*/
int score = 'a';
switch(score){
case 'a':System.out.println("优秀");break;
case 'b':System.out.println("良好");break;
case 'c':System.out.println("及格");break;
case 'd':System.out.println("差生");break;
default:System.out.println("不清楚");
}
//循环:
/*
int i = 0;
while(i<100){
System.out.println("i:"+i);
i++;
}
int j = 0;
do{
System.out.println("j:"+j);
j++;
}while(j<100);
for(int k=0;k<100;k++){
System.out.println("k:"+k);
}
*/
//while 和 do while的区别是,dowhile至少会执行一次
//边界值问:只要限定范围就需要注意边界值
int i = 0;
while(i<0){
System.out.println("i:"+i);
i++;
}
System.out.println(i);
int j = 0;
do{
System.out.println("j:"+j);
j++;
}while(j<0);
System.out.println(j);
//while和if的区别:结束的地方不一样,while条件结束,当满足条件执行完了后还需要进行一次条件判断就while
int a = 1;
int b = 2;
if(a<b){
System.out.println("a<b");
a=3;
}
int c = 1;
int d = 2;
while(c<d){
System.out.println("c<d");
c=3;
}
}
}