Java array after class job

Source: Internet
Author: User

1. The code above can be compiled smoothly, and output a "very strange" result: Ljava.lang.Object; @ba8a1dc, why is this?

Since the Java object array cannot be converted to an string[] array, this means that the array you are converting is an array of type object itself, but you are not going to convert it to an array of string classes, which is of course wrong. When encountering a type conversion error, the first thing to observe is the original type of the object being converted, this need to first convert it into its own type of object, and then according to the object to manipulate the elements inside, again the type of conversion, and sometimes the object of the analysis may have multiple layers of packaging, In the process of conversion, it is necessary to solve its original type in multiple layers, until the final type of the object is obtained, and then convert the type that cannot be decomposed into the object of its own target type.

2. randomly generate 10 numbers, populate an array, then display the contents of the array with a message box, then calculate the array elements and display the results in a message box. Request to design ideas, program flowchart, source code, results, programming summary, etc. published to the blog Park.

Design ideas

To apply for an array of length ten, randomly generate a number of ten, with a For loop control, fill an array, calculate the element's and, message box display array contents

Program Flowchart

SOURCE program code

Import Javax.swing.JOptionPane; Import Class Joptionpane

Import Java.util.Random;

public class Randomnumber {

public static void Main (string[] args) {

TODO auto-generated method stubs

int a[];

int sum=0;

String output= "";

A=new INT[10];

Random rand=new random ();

for (int i=0;i<10;i++)

{

A[i]=rand.nextint (100);

Sum+=a[i];

Output+=string.valueof (A[i]) + "";

}

Joptionpane.showmessagedialog (Null,output, "random number is" + "", joptionpane.plain_message);

Joptionpane.showmessagedialog (Null,sum, "The sum is" + "", joptionpane.plain_message);

System.exit (0); Terminate the program

}

}

Results

Programming summary

Good at summing up knowledge, thinking more.

Java array after class job

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.