Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the example problem of three monks by java

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how java solved the example problem of three monks. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Three monks

1. Title:

There are three monks living in a temple. Their height must be measured. Please use the program to obtain the tallest height of the three monks.

two。 Analysis:

The height is unknown, which is realized by keyboard input. (first guide the package, then create the object)

The keyboard enters three heights and assigns values to three variables

The higher height values of the first two monks are obtained by ternary operator and saved with temporary height variable.

The temporary height value obtained by the ternary operator is compared with the height of the third monk and saved with the maximum height variable.

Output the results.

3. Practice:

The code is as follows (example):

Public class Demo2 {public static void main (String [] args) {/ / do not like ginger but not jealous / / height is unknown, it is realized by keyboard input; / / (first import package import java.util.Scanner;, and then create object) Scanner sc=new Scanner (System.in); / / keyboard input three height values are assigned to three variables Int height1=sc.nextInt (); int height2=sc.nextInt (); int height3=sc.nextInt (); / / use the ternary operator to obtain the higher height values of the first two monks and save them with temporary height variables: int tempheight = height1 > height2? Height1:height2; / / use the ternary operator to obtain the temporary height value and compare it with the height of the third monk, and save it with the maximum height variable; int maxheight=tempheight > height3? Tempheight:height3; / / output the result. System.out.print (maxheight);}} Thank you for reading! This is the end of the article on "how to solve the example problems of three monks in java". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report