Java job 13 (), java job

Source: Internet
Author: User

Java job 13 (), java job

/* Use an array to solve the issue of Series 1, 2, 3, 5, 8, and 13. the Fibonacci series: Fibonacci */package cn. GM; public class array {public static void main (String [] args) {// TODO Auto-generated method stubint 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]) ;}}

  

/* Select method. Arranged from small to large */package cn. GM; public class yiwei {public static void main (String [] args) {// TODO Auto-generated method stubint [] arr = {10,347,657, 38,382, 75, 76, 56,123 44, 84654};/* select method. Ascending Order */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 );}}

  

/* Bubble method. Arranged from small to large */package cn. GM; public class yiwweiM {public static void main (String [] args) {// TODO Auto-generated method stubint [] arr = {10,347,657, 38,382, 75, 76, 56,123 44, 84654};/* bubble method. Ascending Order */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 );}}

  

/* Array of human objects-a bunch of people */package cn. GM; public class personarr {public static void main (String [] args) {// TODO Auto-generated method stub // create array person arr [] = new person [3]; arr [0] = new person ("Zhao Yi", 20); arr [1] = new person ("Ouyang Nana", 17 ); arr [2] = new person ("Family Name", 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 ("name:" + this. name + "Age:" + this. age );}}

  

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: info-contact@alibabacloud.com 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.