百木园-与人分享,
就是让自己快乐。

Learn java step by step day7

1.Assignment operator


2.Detail of assignment opertor


3.Ternary operator

public class TernaryOperator{
	public static void main(String[] args) {
		int a = 10;
		int b = 99;
		int result = a > b ? a++ : b--;
		System.out.println(result);//99
		System.out.println(a);//10
		System.out.println(b);//98
	}
}

4.Detail of ternary opertor

public class TernaryOperatorDetail{
	public static void main(String[] args) {
		int a = 1;
		int b = 2;
		int c = a > b ? 1.1 : 2.2;//no
		int d = a > b ? (int)1.1 : (int)2.2;//yes
        double e = a > b ? a : b;//yes  
	}
}

5.Exercise of ternary operator

public class TernaryOperatorExercise{
	public static void main(String[] args) {
		//实现三个数的最大值
		int n1 = 1;
		int n2 = 2;
		int n3 = 3;
		int max1 = n1 > n2 ? n1 : n2;
		int max2 = max1 > n3 ? max1 : n3;
		System.out.println(\"最大数\" + max2);

		int max = (n1 > n2 ? n1 : n2) > n3 ? (n1 > n2 ? n1 : n2) : n3;
	}
}

6.Operator priority 


7.Naming rules and conventions for identifiers


8.Keyboard input statement

import java.util.Scanner;//把java.util下的Scanner类导入
public class Input{
	public static void main(String[] args) {
		//1.引入/导入Scanner类所在的包
		//2.创建 Scanner 对象 ,new 创建一个对象,体会
		
		Scanner myscanner = new Scanner(System.in);
		//3.接收用户的输入
		System.out.println(\"请输入名字\");
		//当程序执行到 next 方法时,会等待用户输入
		String name = myscanner.next(); //表示接收用户输入
		System.out.println(\"请输入年龄\");
		int name = myscanner.nextInt();//表示接收输入int
		System.out.println(\"请输入薪水\");
		double sal = myscanner.nextDouble();//表示接收用户输入double
		System.out.println(\"人的信息如下:\");
		System.out.println(\"名字=\" + name + \" 年龄=\" + age + \" 薪水=\" + sal);
	}
}

The knowledge learning in the article comes from:

【零基础 快速学Java】韩顺平 零基础30天学会Java_哔哩哔哩_bilibiliicon-default.png?t=M1L8https://www.bilibili.com/video/BV1fh411y7R8?p=32


来源:https://blog.csdn.net/weixin_63088186/article/details/123224159
本站部分图文来源于网络,如有侵权请联系删除。

未经允许不得转载:百木园 » Learn java step by step day7

相关推荐

  • 暂无文章