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

What is the programming method of Java branch structure?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Most people do not understand the knowledge of this article "what is the method of Java branch structure programming", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the method of Java branch structure programming".

1. Enter three integers from the keyboard into num1,num2,num3, sort them, and output them from small to large.

Import java.util.Scanner;public class CompareThreeNumber {public static void main (String [] args) {Scanner scan = new Scanner (System.in); System.out.println ("Please enter your first integer:"); int num1 = scan.nextInt (); System.out.println ("Please enter your second integer:") Int num2 = scan.nextInt (); System.out.println ("Please enter your third integer:"); int num3 = scan.nextInt (); if (num1 = num2) {System.out.println (num3+ "\ t" + num2+ "\ t" + num1) } else {if (num3=num1) {System.out.println (num2+ "\ t" + num1+ "\ t" + num3);} if (num3 > = num2) {System.out.println (num2+ "\ t" + num3+ "\ t" + num1) System.out.println (num3+ "\ t" + num3+ "\ t" + num1);}

two。

Lottery problem

Suppose you want to develop a game to play the lottery, the program randomly generates a two-digit lottery ticket, prompts the user to enter a two-digit number, and then determines whether the user wins or loses according to the following rules.

1) if the number entered by the user matches the actual order of the lottery ticket, the bonus is 10000 yuan.

2) if the number entered by the user matches all the numbers in the lottery, but the order is not the same, the bonus is 3000 yuan.

3) if a number entered by the user meets only one number that matches the lottery ticket in order, the bonus is 1000 yuan.

4) if a number entered by the user satisfies only one number that matches the lottery ticket in a non-sequential case, the bonus is 500 yuan.

5) if the number entered by the user does not match any of the numbers, the lottery ticket will be invalidated.

Train of thought:

1. Generation of random numbers

two。 Determine the range of random numbers

Random number code implementation:

Class IfTest1 {public static void main (String [] args) {int value= (int) (Math.random () * 90x10); System.out.println (value) / / Formula [Math.random b] Math.random () * (b-a+1) + a)}} above is the content of this article about "what is the programming method of Java branch structure". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

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