Java作业十三(2017-11-20)
2024-08-25 16:48:28
/*使用一位数组解决 1 1 2 3 5 8 13 数列问题 斐波纳契数列 Fibonacci*/
package cn.GM; public class array { public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[] = new int[30];
arr[0] = 1;
arr[1] = 1;
for (int i = 2; i < arr.length; i++) {
arr[i] = arr[i - 1] + arr[i - 2];
System.out.println(arr[i]);
} }
}
/* 选择法。从小到大排列 */
package cn.GM; public class yiwei { public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = { 10, 347, 657, 38, 382, 75, 76, 56, 12344, 84654 };
/* 选择法。从小到大排列 */
for (int i = 0; i < arr.length - 1; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
} }
for (int i : arr)
System.out.println(i);
} }
/*冒泡法。从小到大排列*/
package cn.GM; public class yiwweiM { public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = {10, 347, 657, 38, 382, 75, 76, 56, 12344, 84654};
/*冒泡法。从小到大排列*/
for(int i = 0;i < arr.length;i++) {
for(int j = 0;j < arr.length - 1 -i;j++) {
if(arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
} }
for(int i : arr)
System.out.println(i); } }
/*人类对象数组——一堆人*/
package cn.GM; public class personarr { public static void main(String[] args) {
// TODO Auto-generated method stub
//建数组
person arr[] = new person[3];
arr[0] = new person("赵艺",20);
arr[1] = new person("欧阳娜娜",17);
arr[2] = new person("房祖名",32);
for(int x = 0;x < arr.length;x++)
arr[x].getInfo();
} } class person{
private String name;
private int age;
public person(String name,int age) {
this.name = name;
this.age = age;
}
public void getInfo() {
System.out.println("姓名:" + this.name + " 年龄:" + this.age); } }
最新文章
- 关于as3调用js报“null为空或不是对象”错误
- Android手机_软件安装目录
- Mongo DB 安装-及分布式集群部署(初稿)
- POJ 1159 Palindrome 最长公共子序列的问题
- 线性代数(高斯消元):JSOI2008 球形空间产生器sphere
- 关于android多点触控
- [Tool]利用Advanced Installer建立x86/x64在一起的安装程式
- Servlet程序开发-- 过滤器
- iOS开发之监听键盘高度的变化
- 利用Python实现一个感知机学习算法
- SQL---存储过程---sp_addextendedproperty表字段加描述
- 使用javascript中读取Xml文件做成的一个二级联动菜单
- (1)wr703n刷openwrt智能控制--配置wifi
- Jquery weui picker 支持label和value
- leetcode 203. Remove Linked List Elements 、83. Remove Duplicates from Sorted List 、82. Remove Duplicates from Sorted List II(剑指offer57 删除链表中重复的结点)
- 利用AMPScript获取Uber用户数据的访问权限
- CSS实现元素水平垂直居中
- 最新Linux系统Ubuntu16.04搭建HUSTOJ(LAMP环境)
- Activity启动模式(lauchMode)
- I2S接口工作原理
热门文章
- asp.net core 发布到iis session无法传递的问题
- 记录一个EF连接查询的异常:the entity or complex type &#39;x&#39; cannot be constructed in a linq to entities query
- java - day008 -final ,static ,访问控制符.
- MySQL 的安装与使用(一)
- flutter 解析json
- docker启动,重启,停止容器
- vertx的Actor模型实现
- 关于8.0.15版本的mysql下载与安装
- HttpListener 实现web服务器
- SpringBoot的Profiles根据开发环境和测试环境载入不同的配置文件