Java教程

Learn java step by step day7

本文主要是介绍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

这篇关于Learn java step by step day7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!