Simple Java logic code (Logging Platform, Bubble sorting, daffodils, retrieval, recursion), java

Source: Internet
Author: User

Simple Java logic code (Logging Platform, Bubble sorting, daffodils, retrieval, recursion), java
1. Logging in

Simple and small code. To commemorate the past and bless new people.

 1 public static void main(String[] args){ 2     int[] ld = {1,4,2,10,8,9,5}; 3     int max = ld[0]; 4     for(int i = 1;i<ld.length;i++){ 5         if(ld[i]>max){ 6             max=ld[i]; 7         } 8     } 9     System.out.print(max);10 }
2. Bubble Sorting

Or simple small code, Bubble sorting. To commemorate the past and bless new people.

 1 public static void main(String[] args){ 2     int[] ld = {6,10,2,4,11}; 3     int aa; 4     for(int i = 0;i<ld.length-1;i++){ 5         for(int j = 0;j<ld.length-1-i;j++){ 6             if(ld[j]>ld[j+1]){ 7                 aa=ld[j]; 8                 ld[j]=ld[j+1]; 9                 ld[j+1]=aa;10             }11         }12     }13     for(int a = 0;a<5;a++){14         System.out.println(ld[a]);15     }16 }
3. daffodils

Or a simple little code, the number of daffodils. To commemorate the past and bless new people.

Public static void main (String [] args) {int I = 0; System. out. print ("daffodils:"); for (int a = 100; a <= 999; a ++) {int B = a % 10; int c = a/10% 10; int d = a/100; int all = B * B + c * c + d * d; if (all = a) {System. out. print (all + ","); I ++ ;}} System. out. println ("Total" + I + ");}
4. Number of replies

It is also a simple small code, the number of replies. To commemorate the past and bless new people.

Public static void main (String [] args) {String B = "Haha"; for (int I = 0; I <B. length ()/2; I ++) {char first = B. charAt (0 + I); char list = B. charAt (B. length ()-1-i); if (first! = List) {System. out. print ("not the number of replies"); break;} else if (first = list & I = (B. length ()/2-1) {System. out. print ("number of replies ");}}}
5. Recursion

It is also a simple small code and recursion. To commemorate the past and bless new people.

public class Dg{    public int g(int d){        if(d==1){            return d;        }else{            return d*g(d-1);        }    }}
public class Test {    public static void main(String[] args){        Dg d = new Dg();        System.out.print(d.g(6));    }}

 

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.