Home > Java > javaTutorial > How to determine whether two tigers have the same weight in Java

How to determine whether two tigers have the same weight in Java

王林
Release: 2023-05-20 22:25:04
forward
1525 people have browsed it

Two tigers

1. Question:

There are two tigers in the zoo. It is known that the weight of the two tigers is 180kg and 200kg respectively. Please use the program to determine the two tigers. are of the same weight.

2. Analysis:

  • Define two variables to save the weight of the tiger (unit is kg, only the numerical value is reflected here)

  • Use the ternary operator to determine the weight of the tiger. If the weight is the same, return true, otherwise return false

  • Output result

3. Practice:

The code is as follows (example):

public class Demo1 {
    public static void main(String[] args) {
    //不爱生姜不吃醋
        //定义两个变量用于保存老虎的体重(单位为kg,这里只体现数值即可)
        int weigth2=180;
        int weight2=200;
        //用三元运算符实现老虎体重的判断,体重相同,返回true,否则返回false
        boolean b= weigth2 == weight2 ? true:false;
        //输出结果
        System.out.println(b);
    }
}
Copy after login

The above is the detailed content of How to determine whether two tigers have the same weight in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template