本篇内容主要讲解“怎么用java代码实现数组元素顺序颠倒”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用java代码实现数组元素顺序颠倒”吧!
定义一个数组a[n],用java代码实现数组元素顺序颠倒
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),
(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; i++) { int tmp = a[i];
a[i] = a[len - 1 - i];
a[len - 1 - i] = tmp;
}
}
}
金额转换,阿拉伯数字的金额转换成中国货币传统的计算形式
如:输入(¥1001)——输出(一千零一元整)。
public class Test { private static final char[] data =
new char[] { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' }; private static final char[] units =
new char[] { '元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿' }; 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();
}
}
到此,相信大家对“怎么用java代码实现数组元素顺序颠倒”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/javazhiyin/blog/4628213