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