Learn java step by step day7
2022/3/3 1:17:30
本文主要是介绍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_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1fh411y7R8?p=32
这篇关于Learn java step by step day7的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-27MQ底层原理资料详解:新手入门教程
- 2024-11-27MQ项目开发资料入门教程
- 2024-11-27RocketMQ源码资料详解:新手入门教程
- 2024-11-27本地多文件上传简易教程
- 2024-11-26消息中间件源码剖析教程
- 2024-11-26JAVA语音识别项目资料的收集与应用
- 2024-11-26Java语音识别项目资料:入门级教程与实战指南
- 2024-11-26SpringAI:Java 开发的智能新利器
- 2024-11-26Java云原生资料:新手入门教程与实战指南
- 2024-11-26JAVA云原生资料入门教程