if語句實(shí)現(xiàn)獲取兩個(gè)數(shù)據(jù)較大值
package com.itheima_02;
import java.util.Scanner;
/*
* 鍵盤錄入兩個(gè)數(shù)據(jù)朽合,獲取這兩個(gè)數(shù)據(jù)的最大值
*
* 分析:
* A:看到鍵盤錄入饱狂,我們就應(yīng)該想到鍵盤錄入的三個(gè)步驟
* 導(dǎo)包,創(chuàng)建鍵盤錄入對(duì)象讲婚,接收數(shù)據(jù)
* B:獲取這兩個(gè)數(shù)據(jù)的最大值筹麸,其實(shí)就是比較看哪個(gè)數(shù)據(jù)大而已
* C:把大的結(jié)果輸出即可
*
* 導(dǎo)包:
* A:手動(dòng)導(dǎo)入
* B:點(diǎn)擊鼠標(biāo)自動(dòng)生成
* C:快捷鍵(推薦)
* ctrl + shift + o
*/
public class IfTest {
public static void main(String[] args) {
//創(chuàng)建鍵盤錄入對(duì)象
Scanner sc = new Scanner(System.in);
//接受數(shù)據(jù)
System.out.println("請(qǐng)輸入第一個(gè)數(shù)據(jù):");
int a = sc.nextInt();
System.out.println("請(qǐng)輸入第二個(gè)數(shù)據(jù):");
int b =sc.nextInt();
//if語句格式2完成該功能
/*
if(a > b) {
System.out.println("大的值是:" + a);
}else {
System.out.println("大的值是:" + b);
}
*/
//兩個(gè)數(shù)據(jù)比較完畢后,我拿最大值可能需要做其他的操作
//定義一個(gè)變量用于接受較大的值
int max;
if(a > b) {
max = a;
}else {
max = b;
}
// max += 100;
System.out.println("大的值是:" + max);
}
}