java笔记

运算符

A、概念

​ 对常量和变零进行运算

B、 常用运算符

​ a、算数运算符

​ b、赋值运算符

​ c、关系运算符

​ d、逻辑运算符

​ e、三元运算符

C、逻辑运算符&&与&的区别

​ a:结果都一样

​ b:&&相当于短路,左边是false,右边不执行

​ &无论左边是false或true ,右边都会执行

D、逻辑运算符||与|的区别

​ a:结果都一样

​ b:|| 相当于短路,左边是false,右边不执行

​ |无论左边是false或true ,右边都会执行

例:

package cn.llhc.det01;
	public class OperatorDome06 {
	public static void main(String[] args){
		int x = 10;
		int y = 20;
		int z = 30;
		System.out.println((x > y)&&(y>z));//fslse
		System.out.println((x > y)||(y<z));//true
		System.out.println((x > y)&(y>z));//fslse
		System.out.println((x > y)|(y<z));//true
		System.out.println((x++ > 10)&&(++y<20));//true
	}	
}

在这里插入图片描述

取余运算跟左边的正负无关,只与右边的有关

流程图

A、顺序结构

​ 按照顺序逐行执行

B、循环结构

a、if语句

​ if(关系表达式){

   语句块

​ }else{

​ 语句块2

​ }

例:if语句实现判断王者荣耀段位
package cn.llhc.det01;
import java.util.Scanner;
public class IfElseIfDemo {
	public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	System.out.println("请输入你的rank分(0分-100分)");
	int rank=sc.nextInt();
	if ((rank<=100)&&(rank>=90)){
			System.out.println("你段位为最强王者!");
	}else if((rank<90)&&(rank>=80)){
		System.out.println("你段位为星耀!");
	}else if((rank<80)&&(rank>=70)){
		System.out.println("你段位为钻石!");
	}else if((rank<70)&&(rank>=60)){
		System.out.println("你段位为黄金!");
	}else if((rank<0)||(rank>100)){
		System.out.println("请重新输入!");
	}
	else if (rank<60){
		System.out.println("你的段位为黑铁!");
	}else{
		System.out.println("輸入錯誤!!");
	}	
  }
}

在这里插入图片描述

b、switch语句

​ switch(变量/表达式){

​ case字面值1:语句块1;break;

​ case字面值2:语句块2;break;

​ case字面值n:语句块n;break;

}default{

​ 语句块

}

例:根据用户输入的年份,月份,判断该年该月有多少天
使用Switch编写代码
package cn.llhc.det01;
import java.util.Scanner;
public class SwitchDemo {
		public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		System.out.println("请输入年份、月份:");
		int y = sc.nextInt();
		int m = sc.nextInt();
		int day=31;
		switch(m){
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				break;
			case 2:
				day=(y%4 == 0 && y%100!=0 || y%400 == 0)?29:28;
					break;
			case 4:
			case 6:
			case 9:
			case 11:
				day=30;
				break;	
			default:System.out.println("輸入有誤,請重新輸入!");	
		}	
		System.out.println(y+"年"+ m +"月有"+day+"天");
		sc.close();
}
}

在这里插入图片描述
c、for语句

for(初始化语句;判断条件语句;控制条件语句){

循环体语句

}

例:输出1-10,1-100偶数和
package cn.llhc.det01;
public class ForDemo {
		public static void main(String[] args){
			for (int i=1; i<11;i++){
				System.out.println(i);
			}
			int num=10;
			for (int i = 1; i < 11; i++){
				num+= i ;
			}	
int nu=0;
		for (int i = 1; i <=100; i++){
			//判断是不是偶数
			if(i%2==0){
				nu+=i;
			}
		}
		System.out.println(nu);
	}
}

在这里插入图片描述

窗体

​ JFrame—窗躰-----相框

​ JPanel----画布—相片

導包:

​ 1、手動导包 import…

​ 2、自動导包 ctrl+shift+o

​ 3、点击红色叉号

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值