package cuteSnow;

public class HelloWorld {
// 遍历数组里面的每个数字
public static void print(int[] array){
String tip = "数组中每个元素分别为:";
for(int i = 0; i<array.length; i++) {
int temNum = array[i];
tip = tip + temNum +" ";
}
System.out.print(tip);
}
// 判断给定数据是否为6的倍数
public static void sixMultiple(int[] array) {
String tip = "6的倍数有:";
for(int i = 0; i<array.length; i++) {
int temNum = array[i];
if( temNum % 6 == 0) {
tip = tip + temNum +" ";
}
}
System.out.print(tip);
}
// 将数组第一个数字和最后一个数字对调
public static void exchange(int[] array) {
String tip = "数组第一个数字和最后一个数字对调之后的数组为:[";
int tem = array[array.length - 1];//最后一个的值存起来
array[array.length - 1] = array[0];
array[0] = tem;
for(int i = 0; i<array.length; i++) {
int temNum = array[i];
tip = tip + temNum;
if(i < array.length-1) {
tip = tip + ",";
}
}
System.out.print(tip+"]");
}
// 将数组的元素倒序排列
public static void desc(int[] array) {
String tip = "数组的元素倒序排列为:[";
for(int i = 0; i<array.length/2; i++) {
int tem = array[i];
array[i] = array[array.length - i - 1];
array[array.length - 1 - i] = tem;
}
for(int i = 0; i<array.length; i++) {
int temNum = array[i];
tip = tip + temNum;
if(i < array.length-1) {
tip = tip + ",";
}
}
System.out.print(tip+"]");
}
//求1000以内的质数,存放到数组中
public static void prime() {
String tip = "1000以内的质数组合成的数组为:[";
int[] prime = new int[50]; // 最多存放50个
int count = 0;
for(int i = 2;i <= 1000;i++) {
boolean isPrime = true;
for(int k = 2;k < i;k++) {
if(i % k == 0) {
isPrime = false;
break;
}
}
if(isPrime) {
prime[count] = i;
count++;
if(count >= prime.length) {
break;
}
}
}
for(int i = 0; i < count; i++) {
int temNum = prime[i];
tip = tip + temNum;
if(i < count-1) {
tip = tip + ",";
}
}
System.out.print(tip+"]");
} // 主函数
public static void main(String[] args) {
// System.out.println("helloworld");
int[] array = { 29, 90, 48, 92};
// 调用
print(array);
System.out.print("\n");
sixMultiple(array);
System.out.print("\n");
exchange(array);
System.out.print("\n");
desc(array); // 由于数组时引用类型,所以此处是数组值受exchange(array)方法的影响值为[92,90,48,29]
System.out.print("\n");
prime();
}
// 上述运行结果
数组中每个元素分别为:29 90 48 92
6的倍数有:90 48
数组第一个数字和最后一个数字对调之后的数组为:[92,90,48,29]
数组的元素倒序排列为:[29,48,90,92]
1000以内的质数组合成的数组为:[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229]

}

最新文章

  1. 查看数据库表的数据量和SIZE大小的脚本修正
  2. 常用的java类型转json的转换类
  3. Eclipse仿Visual AssistX 编辑着色插件
  4. http://highscalability.com/blog/2015/5/18/how-mysql-is-able-to-scale-to-200-million-qps-mysql-cluster.html
  5. C#.NET序列化XML、JSON、二进制微软自带DLL与newtonsoft(json.net)
  6. LNMP编译安装教程
  7. Python自动化 【第十篇】:Python进阶-多进程/协程/事件驱动与Select\Poll\Epoll异步IO
  8. hdu_1875_畅通工程再续 prim和kruskal
  9. Javascript Promise 学习笔记
  10. FreeBsdb FAMP Lamp环境
  11. JavaScript表单验证年龄
  12. JavaEE(16) - JPA生命周期及监听器
  13. 第一个Android crackme(2016-05)
  14. SourceTree 无法查看组织仓库
  15. 【Spring】面向切面之AOP
  16. echarts.js--前端可视化数据图形
  17. Git:git diff 命令详解
  18. Linux下设置python脚本文件为服务
  19. webbench的安装
  20. js 读写 cookie 简单实现

热门文章

  1. 【codeforces 727D】T-shirts Distribution
  2. hdu 1556 线段树区间延迟更新好题
  3. nodejs-NPM基本使用
  4. rails 修改数据库之后注意修改controller
  5. 01背包问题(回溯法)python实现
  6. linux块设备的IO调度算法和回写机制
  7. 【Java基础】--再谈面向对象
  8. unity3D游戏开发实战原创视频讲座系列9之塔防类游戏开发第一季
  9. 杂项-DB:DW/DWH(数据仓库)
  10. WebService CXF学习:复杂对象传递(List,Map)