First, the appearance of Ljava.lang.Object; What is the reason for @ba8a1dc? What does that mean?
A: The problem occurs when the SQL statement executes a query with only one column, and when there are multiple columns, there is no problem with the array, if only one column defaults to String or another type. Type conversion errors can only be strongly converted to Object, and then values are added to the ToArray () method by adding a String array and then outputting.
Second, the program will generate a number of random numbers into the array and sum
Design Idea : Import The Random class, generate stochastic number, import joptionpane class, use message box, output information; create int Type array and set the length of ten, used to store random numbers;random random=new random (); Create a random object in the for Call in the loop, generate A random number,r[i]=random.nextint (), and the final sum of the output results.
Program Flowchart:
Source:
Package com;
Import java.util.random;//Importing the Random class
Import javax.swing.joptionpane;//Importing Joptionpane class
public class Random_ {
public static void Main (string[] args) {
int r[]=new int[10]; Creates a new array object of type int, with a length of 10
The initialization of int s=0;//
Random random=new random ();//Create Random Object
for (int i=0;i<10;i++)//Use a loop to generate 10 random numbers and deposit them in the array
{
R[i]=random.nextint ();//Generate random numbers
s+=r[i];//summation
}
Joptionpane.showmessagedialog (
NULL, "The contents of the array are:" +r[0]+ "" +r[1]+ "" +r[2]+ "" + "" +r[3]+ "" +r[4]+ "" +r[5]+ "" +r[6]+ "" +r[7]+ "" +r[8]+ "" +r[9 ");
Output an array element using a message box
Joptionpane.showmessagedialog (
NULL, "The and of the elements of the array is:" +s);
Use a message box to output the array's and
}
}
Results:
Programming Summary: There are two ways to generate random numbers, I use this one more flexible, there is no upper and lower limit but you can add the upper limit, you need to create a random object, another can be limited; Create an array object when creating a new array to open up space.
Random numbers are stored in arrays and summed