Java学习日记 DAY3

1.今天的学习是从下午的胡思乱想开始的。
1)计算机中只对补码进行运算,看下面代码(可以进行思考)

public class buma {
	public static void main(String[] args) {
		int a=456;
		System.out.print((byte)a);//输出结果为-56
	}

运算过程为:456补码>-byte只取后八位>-码转为原码>-输出。
2)原码、反码只能表示-127~127;
补码可表示-128~127
-128只有补码,为:1000 0000
原因可自行百度
3)原码——>补码
补码——>原码 二者转换方式一样(取反加一)
2.ASCII表
48–0
65–A
97–a
3.字符、字符串参与运算(见下面代码)

	public static void main(String[] args) {
		System.out.println('a'+1);//输出98;注意字符用单引号
		System.out.println("hello"+'a'+1);//输出helloa1
		System.out.println('a'+1+"hello");//输出98hello
		System.out.println("2+2="+2+2);//输出2+2=22
		System.out.println(2+2+"=2+2");//输出4=2+2
	}

注意字符串前后的“+”是用来做拼接的,后面的“+”都遵循线面“+”的运算规则
而前面的“+”用来做加法是可以的
4.if结构

	public static void main (String[] args) {
		Scanner in=new Scanner(System.in);
		int age=in.nextInt();
		System.out.println("你的年龄是"+age);
		if(age<=25)
		{
			System.out.println("年轻是美好的");
		}
		else
		{
			System.out.println("年龄决定了你的精神境界");
		}
		
	}

1)三个数字的比较(嵌套)

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int a=in.nextInt();
	    int b=in.nextInt();
	    int c=in.nextInt();
	    int max;
	    if(a<b) {
	    	if(b>c) {
	    		max=b;
	    	}
	    	else {
	    		max=c;
	    	}
	    }
	    else {
	    	if(a>c) {
	    		max=a;
	    	}
	    	else {
	    		max=c;
	    	}
	    	
	    }
	    System.out.println(max);
	}

2)级联

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int a=in.nextInt();
		int b = 0;
		if(a<0) {
			b=1;
		}
		else if(0<a&a<2) {
			b=2;
			
		}
		else if(a>2) {
			b=3;
		}
		System.out.println(b);
	}

5.switch

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int type=in.nextInt();
		
		switch(type) 
		{
		case 1://输入1 输出晚上好
		case 2://输入2 输出晚上好
			System.out.println("晚上好");
		break;
		}
	}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值