JAVA basics for their own weaknesses 02, java weaknesses 02

Source: Internet
Author: User

JAVA basics for their own weaknesses 02, java weaknesses 02
Cycle A: daffodils.

ClassShuiXianHua

{

Public static void main (String [] args)

{

For (int I = 101; I <1000; I ++)

{

Int ge = I % 10;

Int shi = I/10% 10;

Int bai = I/100% 10;

If (ge * ge + shi * shi + bai * bai = I)

System. out. print (I + "");

}

}

}

Result:


B: count the number of stacks that can be stacked to the height of Mount Everest.

ClassZhuMuLangMa

{

Public static void main (String [] args)

{

Int end = 884800;

Int start = 1;

Int count = 0;

Do

{

Start * = 2;

Count ++;

} While (start <= end );

System. out. println ("stacked" + count + "times higher than the height of Mount Everest ");

}

}

Result:


C: Triangle

ClassZhengSanJiao

{

Public static void main (String [] args)

{

For (int I = 0; I <5; I ++)

{

For (int j = I; j <= 5; j ++)

{

System. out. print ("");

}

// System. out. println ();

For (int j = 0; j <= I; j ++)

{

System. out. print ("*");

}

For (int j = 0; j <I; j ++)

{

System. out. print ("*");

}

System. out. println ();

}

}

}

Result:


D: inverted triangle

ClassDaoSanJiao

{

Public static void main (String [] args)

{

For (int I = 0; I <5; I ++)

{

For (int j = 0; j <I; j ++)

{

System. out. print ("");

}

// System. out. println ();

For (int j = I; j <5; j ++)

{

System. out. print ("*");

}

For (int j = I; j <4; j ++)

{

System. out. print ("*");

}

System. out. println ();

}

}

}

Result:


Array A Definition Format:

One-dimensional

Int [] arr = new int [6];

Intarr [] = new int [6];

Int [] arr = new int [] {1, 2, 3, 4 };

Int [] arr = {1, 2, 3, 4 };

 

Two-dimensional

A: int [] [] arr = new int [3] [2];

B: int [] [] arr = new int [3] [];

C: int [] [] arr = {, 3}, {}, {6, 7, 8, 9 }};

B application:

Query of one-dimensional arrays

ClassFind

{

Public static void main (String [] args)

{

Int [] arr = new int [] {1, 2, 3, 4 };

System. out. println (findArr (arr, 4 ));

}

Public static int findArr (int [] arr, int x)

{

For (int I = 0; I <arr. length; I ++)

{

If (arr [I] = x)

Return I;

}

Return-1;

}

}

Result:


Search for two-dimensional arrays

ClassShuiXianHua

{

Public static void main (String [] args)

{

Int [] [] arr = {1, 2, 3}, {4, 5}, {6, 7, 8, 9 }};

SortArr (arr );

}

Public static void sortArr (int [] [] arr)

{

For (int I = 0; I <arr. length; I ++)

{

For (intj = 0; j <arr [I]. length; j ++)

{

System. out. print (arr [I] [j] + "");

}

System. out. println ();

}

}

}

Result:


Java memory Diagram

STACK: local variable. release immediately after use

Heap: stores new items, including address values, initialization default values, and garbage collection mechanism.

Method Area: storage method, String constant pool, static area ()

Local Method Area: system-related methods

Register: executed by the CPU

 

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.