How to reverse the order of array elements with java code
This article focuses on "how to use java code to reverse the order of array elements", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to reverse the order of array elements with java code.
Define an array a [n] and reverse the order of array elements with java code
Import java.util.Arrays;public class Test {
Public static void main (String [] args) {
Int [] a = new int [] {(int) (Math.random () * 100), (int) (Math.random () * 100) (int) (Math.random () * 100)} System.out.println (Arrays.toString (a)); swap (a); System.out.println (Arrays.toString (a));}
Public static void swap (int a []) {
Int len = a.length
For (int I = 0; I < len / 2; iTunes +) {
Int tmp = a [I]; a [I] = a [len-1-I]; a [len-1-I] = tmp;}
The amount of Arabic numerals is converted into the traditional calculation form of Chinese currency.
Such as: input (RMB 1001)-output (RMB 1001).
Public class Test {
Private static final char [] data = new char [] {'zero', 'one','II','3', 'restaurant','Wu','Lu','Qi', 'Qing', 'nine'}
Private static final char [] units = new char [] {'yuan', 'pick', 'hundred', 'thousand', 'ten thousand', 'pick up', 'hundred', 'thousand', 'billion'}
Public static void main (String [] args) {System.out.println (convert (135689123));}
Public static String convert (int money) {StringBuffer sbf = new StringBuffer ()
Int unit = 0
While (money! = 0) {sbf.insert (0, units [unit++])
Int number = money% 10; sbf.insert (0, data [number]); money / = 10;}
Return sbf.toString ();}} at this point, I believe you have a deeper understanding of "how to reverse the order of array elements with java code", so you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!