Code for the three-mesh operator and array method in Java and the size of the integer comparison

Source: Internet
Author: User

This article brings you the content is about Java in the three-mesh operator and array methods and integer comparison size code, there is a certain reference value, the need for friends can refer to, I hope to help you.

code block

The code is as follows, for example:

class, imported Java package Import java.util.scanner;//I only have the main method listed public static void Main (string[] args) {Scanner Scanner = NE        W Scanner (;                Receive user input System.out.println ("Clear input 1th number:");                int a = Scanner.nextint ();                SYSTEM.OUT.PRINTLN ("Clear input 2nd number:");                int b = Scanner.nextint ();                SYSTEM.OUT.PRINTLN ("Clear input 3rd number:");                int c = Scanner.nextint ();                SYSTEM.OUT.PRINTLN ("Clear input 4th Number:");        int d = Scanner.nextint (); The trinocular operation solves int m = a > B?        A:B; int n = c > d?        C:d; int x = m > n?        m:n;        System.out.println ("max=" + x);                The branching method solves the int t;  if (a > B) {t = A;  A = b;              b = t;              } if (a > c) {t = A;              A = C;              c = t;               } if (a > D) {t = A;               A = D;               d = t;   }              if (b > c) {t = b;               b = C;               c = t;               } if (b > D) {t = b;               b = D;               d = t;               } if (C > D) {t = C;               c = D;               d = t;        } System.out.println ("max=" + D);                Array method to solve int p[] = new INT[4];            for (int i = 0; i < 4; i++) {System.out.println ("Please enter" + (i + 1) + "number:");        P[i] = Scanner.nextint (); } for (int i = 0; i < 3; i++) {if (P[i] > p[i + 1]) {//Here you can also set a                Intermediate variable t to exchange p[i] = P[i] + p[i + 1];                P[i + 1] = P[i]-p[i + 1];            P[i] = P[i]-p[i-1]; }} System.out.println ("max=" + p[3]);//The largest is placed at the end of the array}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.