java array question.

java array question.

View Answers

July 13, 2009 at 2:21 PM

Hi Friend,

Try the following code:

public class RandomNumberArray {

private static void showNumbers() {
int randomNumbers=0;
int min = -5;
int max = 45;
int counter=0;
String st="";
int sum=0;
int[] ranNum = new int[50];

for ( int i = 0; i < ranNum.length; i++) {
counter++;
ranNum[i] = (int)(Math.random() * (max - min + 1) ) + min;
randomNumbers=ranNum[i];
st=Integer.toString(randomNumbers);
sum+=ranNum[i];

if(counter==10){
st+="\n";
}
if(counter==20){
st+="\n";
}
if(counter==30){
st+="\n";
}
if(counter==40){
st+="\n";
}
System.out.print(st+" ");
}
int average=sum/50;
System.out.println("\n"+"Average of Numbers is: "+average);
}



public static void main(String[] args) {
showNumbers();
}

}
Thanks









Related Tutorials/Questions & Answers:
Question in Array Implementation (java) ??!
Question in Array Implementation (java) ??!  Good Morning EveryOne I have Q in Java - and if any One have the Answers please tall me ??!! Question... stores list of â??PhoneEntryâ?? objects. Use an array of size (MAXSIZE = 1000
java array question. - Java Beginners
java array question.  I need help with this: Create a program that will generate 50 random numbers between the range of -5 and 45 and store them in an array. Have the program then print the numbers in rows of 10 and calculate
Advertisements
Question Java>?
Question Java>?  **ïâ??· Create a new class called Bank and in the main method use class Account (lab 4) to create an array of 10 accounts. ïâ... in array
please help me to solve this question about array
please help me to solve this question about array  write a program thatt stores vowels (a,e,i,o and u)in an array. Ask the user to enter any character. The program should ignore the case of that character (uppercase or lowercase
Java array
Java array   How can one prove that the array is not null but empty
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
java question
java question  Hello sir/mam, In collection there is method called toArray() which is used to convert collection into array at tat time array is used 2 store diffferent objects,how is it possible can you describe it briefly
java question
java question  Hello sir/mam, In collection there is method called toArray() which is used to convert collection into array at tat time array is used 2 store diffferent objects,how is it possible can you describe it briefly
java question
java question  Hello sir/mam, In collection there is method called toArray() which is used to convert collection into array at tat time array is used 2 store diffferent objects,how is it possible can you describe it briefly
java question
java question  Hello sir/mam, In collection there is method called toArray() which is used to convert collection into array at tat time array is used 2 store diffferent objects,how is it possible can you describe it briefly
Java Array
Java Array   a) Write an array program that perform the following: i) Declares a String array initialized with the following strings: ââ?¬Å...?¬Â?. ii) Write a loop that displays the contents of each element in the array
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
Question in Java ??
Question in Java ??   Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number squrfoot
Question in Java ??
Question in Java ??  Welcome every One ,I have Q in Java : Write aprogram that print the falewing table using SQRT method in the Math Class? Number 0 ,2, . . . ,18,20 squrfoot 00000 1.4142 5.2426 5.4721
java array
java array  q4.array Write a program that accepts two arrays, an array of fruit names and an array of price of fruits, and a fruit name and returns the price of the fruit. (Assume that a price in the second array corresponds
java array
java array  write a java method that takes an array of float values...)){ System.out.println("There are duplicate elements."); Float array...++){ array[i]=new Float(arr[i]); } Set<Float>
Question on java
Question on java  why java is not purely oop?   java is not purely OOP because 1.) Multiple Inheritance is not supported.ADS_TO_REPLACE_1 2.) It uses primitive data type. 3.) static method can be called without
java question
java question   Create a class called Complex to perform arithmetic operations with complex numbers. 1- Use double variables to represent the fields of the class. 2- Provide a no-argument constructor with default values in case
java question 15/03/2014
java question 15/03/2014  Hi Q)my array size is 10, then how can i identify class A object from array. Q) how jvm know a particular object is serialize or not . Q) i have a table in that table some data duplicate than how
java question :)
java question :)  write java program to use vector in ArrayList with add, remove,sort   import java.util.Vector; public class... Element MUAYAD"); vc.add("Vector Element JAVA"); vc.add("Vector Element
C/C++/JAVA Question on function
C/C++/JAVA Question on function  "Write a function to find out common alphabets between two arrays. Length of array is not fixed and may contain other data type also.ââ?¬Â? Question can be solved in C,C++ or JAVA
a java question
a java question  A thief Muthhooswamy planned to escape from *** jail... to cross 'N' number of walls where height of each wall is given in an array. Write... array where the height of each wall is provided, the ith element is (1<=i<
array password - Java Beginners
array password  i had create a GUI of encryption program that used the array password. my question is can we do the password change program? i mean we change the older password with the new password
java array
java array Two cells is a matrix will be called connected if they are adjacent...], a[3,2], a[3,3] } elements with weight 6 Problem: Implement Java code which takes 2 dimensional integer array as input and prints out heaviest island
Java Class Question?
Java Class Question?  b.Write an application that prompts the user... array as $2.00, $2.50, $3.25, and $4.50 respectively. Allow the user to choose... { public static void main(String[] args) { double array
jagged array in java
jagged array in java   jagged array in java with example
Java Class Question?
Java Class Question?  Write an application that prompts the user to make a choice for a Coffee cup size, S for Small, T for Tall, G for Grande and V... array as $2.00, $2.50, $3.25, and $4.50 respectively. Allow the user to choose
java question
java question  the purpose of defining multiple constructor in java
java question
java question  find the 127 twin pair in java
JAVA QUESTION
JAVA QUESTION  How to view image on Frame in swing(or)awt in Java
JAVA QUESTION
JAVA QUESTION  How to view image on Frame in swing(or)awt in Java
JAVA QUESTION
JAVA QUESTION  How to view image on Frame in swing(or)awt in Java
java question
java question  what is the difference between path and classpath in java
java question
java question  How to find the longest and shortest line from the file in case of java and java program should read the filename from the keyboard
java question
java question  wats dynamic dispatching
Core Java Interview Question, Interview Question
Core Java Interview Question Page 12  ... collections of objects. Question: How does Java handle integer overflows... a growable array of objects Question: What modifiers may be used with an inner
java question
java question  Please, give me sample program for insert Audio(sound) on Frame in swing in java
java question
java question  how to write a java program that, given a friend name , display the phone number and the email address for that friend
java question
java question  anyone provide the code to call c++ function from java   Here you will find details how to implement the c++ into the java. http://www.javaworld.com/javatips/jw-javatip23.html
Java Question
Java Question  can u give me one expample in which conditions we... in java includes only abstract methods i.e. methods have signatures only (or we... in java defines that it must be implemented by any class to make use of it. One
java question
java question  input any number and check if sum of alternate digit is palindrome
java question
java question  what are the exactly J2EE concepts.. struts and hybernates coming under which catagiry
java question
java question  i wrote to java code to get data populated in the Revision field of table InventDim 2.Failing to successfully do the above, i tried to use the ConfigId field of table InventDim for the same purpose, by labeling
java question
java question  how to create date and time based pgm in java... in db table if date and time crossed automatically update in the db and inform to login user as pop ups   http://www.roseindia.net/jsp/loginstatus.shtml
java question
java question  Can any one send me the source code to get confirmation after the successful registration to our mobile
java question
java question  when we use the Abstract class and interface?   Please visit the following link: Abstract class and Interface
java question
java question  sir, can you give me the code for online banking using netbeans and mysql in j2ee with its database connectivity
java question
java question  sir, can you give me the code for online banking using netbeans and mysql in j2ee with its database connectivity
java question
java question  I am converting a .net website into java one. Can you help me how to code things step by step. project name - src -java -main -webapp - common - jsp - css - images - javascripts I
Java question
Java question  Write a program that converts a (C to F Converter from 0 - 20) and writes the output to a file instead of the screen. Open the file in Notepad to confirm the output

Ads