kwame
random numbers
1 Answer(s)      2 years and 11 months ago
Posted in : Java Beginners

write a program to accept 50 numbers and display 5 numbers randomly
View Answers

June 18, 2010 at 3:44 PM


Hi Friend,

Try the following code:

import java.util.*;
class RandomNumberExample {
static Random generator = new Random();
public static int get (int[] array) {
int rnd = generator.nextInt(array.length);
return array[rnd];
}
public static void main(String[]args){
int arr[]=new int[10];
Scanner input=new Scanner(System.in);
System.out.println("Enter 10 numbers: ");
for(int i=0;i<10;i++){
arr[i]=input.nextInt();
}
System.out.println();
System.out.println("Random numbers are: ");
int random[]=new int[5];
for(int i=0;i<random.length;i++){
random[i] = RandomNumberExample.get(arr);
System.out.println(random[i]);
}
}
}

Thanks









Related Pages:
random numbers
random numbers  hi.. i am creating a website and on feedback form to authenticate user i want to generate a random number on label.if user types that number correctly in textbox then he is allowed to submit feedback otherwise
Generate Random Numbers
Generate Random Numbers  hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit
random numbers - Java Beginners
random numbers  write a program to accept 50 numbers and display 5 numbers randomly  Hi Friend, Try the following code: import...(); System.out.println("Random numbers are: "); int random[]=new int[5]; for(int i=0;i
Random numbers - Introduction
Java NotesRandom numbers - Introduction When to use random numbers There are many types of programs that use random numbers. Game programs use them... numbers. You might want to use random numbers to change the appearance
random numbers - Java Beginners
random numbers  Hello i need this code to be modified for me to display the random numbers, but not twice or more. I mean i need a number...("Random numbers are: "); int random[]=new int[5]; for(int i=0;i  Hi
Random numbers - Development process
Random numbers  hi, How to generate unique random numbers between range like(10 to 50)  Hi friend, class RandomNumber { public static void main(String[] args) { //set the variable aNumber
Random Numbers - shuffling
is described at the bottom. Shuffling: Random numbers without replacement The random number methods generate numbers with replacement. This means... numbers - intro Random numbers - API Copyleft 2005 Fred Swartz MIT
generate random numbers and display the largest
generate random numbers and display the largest  Hi, I am using... creates an array and fills it with random ints, prints the contents... ArrayRandom{ public static void main(String args[]){ Random r = new Random
generating random numbers - Java Beginners
generating random numbers  We would like to be able to predict tomorrow's price of a share of stock. We have data on past daily prices. Based on that we will make a prediction. Our plan is to use a weighted average of the 5 most
Random in jsp
Random in jsp          Random numbers are the numbers that are determined entirely by chance. User does not have any control over the working of random numbers
Generate array of random numbers
Generate array of random numbers You can generate a random number either...() but it is better to use Random class. If you want to generate a series of random numbers...(); } System.out.println(); System.out.println("Random numbers are: "); int random
Generate array of random numbers without repetition
Generate array of random numbers without repetition In the previous section, you have learnt how to generate an array of random numbers from the given array... created an application that will generate the array of random numbers without
Generating Random Numbers to Fill array. Java Beginner needing help!
Generating Random Numbers to Fill array. Java Beginner needing help!  ... a program that produces random permutations of the numbers 1 to 10. eg... the permuted numbers. Make a second array and fill it with the numbers 1 to 10
getting random number in java
getting random number in java  getting random number in java Hi everyone, i am trying to get a random number in a particular range. for example random numbers between 1 to 100 in Java. Though i m new to Java, i have tried many
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to use a File object and print even numbers from two to ten. Then using RandomAccessFile write numbers from 1 to 5. Then using seek () print only the last 3 digits
Random numbers - API
class often produce random numbers in a more convenient form, but requires creating... directly useful numbers from the Random class. java.util.Random class To use... The Math.random() method returns random double numbers in the range >=0.0
Generating Random Number
;  In many places you need random numbers to fulfill your requirements. Java provides classes to help you in generation random numbers for your application. Random Number is the frequently used to generate numbers
PHP Random Number
PHP Generate Random Numbers: A random number is becoming more useful.... To generate random number, PHP provides rand() function. ... Value A random value  Example : <
understanding buttons :JSP random no program
understanding buttons :JSP random no program  I hav java random... random no between 100 and 200 on loading and on clicking submit button it ives... "no is greater" please help me to understand buttons .thank you java code for random
Javascript random number - Design concepts & design patterns
are retreived from database.I have to generate random numbers corresponding to every... one group there will be 10 rows and their random numbers will be same.Then next 10 rows' random numbers will be same.coloumn name is LOT NO.After displaying
MySQL random
and thereafter we can show the result of it. Numbers generated are in the random... MySQL random       In MySQL we can get the random records by using the method RAND() of MySQL
Javascript random number - Design concepts & design patterns
are retreived from database.I have to generate random numbers corresponding to every... group there will be 10 rows and their random numbers will be same.Then next 10 rows' random numbers will be same.coloumn name is LOT NO.After displaying
MySQL random number
versions of RAND() function : first RAND() and second is RAND(X). Random numbers... is not a perfect random number but it is very close to the perfect random numbers. Here.... Numbers generated are in the random order which means that they lack any pattern
Default constructor generate two random equations
Default constructor generate two random equations  Need to create a default constructor in a programmer defined class that generates a random question, addition or subtraction. And when adding the numbers must be random from 0-12
Assigning ordinate numbers - JSP-Servlet
, For random number: import java.util.*; public class OrdinalNumber { public static...[] args) { OrdinalNumber number = new OrdinalNumber(); Random r=new Random
JavaScript array get elements at random
of the array. For generating random numbers we have used the Math.random() function... random numbers between value "0" and "9". Each and every time... JavaScript array get elements at random   
Randomizer
; In this example we are discussing how to generate the random numbers... random numbers by apply some mathematical operations onto them and display 10 random numbers on the console. Description of program:  In the given
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
Random classes
Random classes  Hello... What is Random class? What's the purpose
random number
random number  Sir could u please send me the code registration form of roseindia.net with image varification
random number
random number   Please How do I generate a program that gives me random integer from 115 to 250? Using java.util.random. Thank you very much!  ...[] args){ int min = 115; int max = 250; Random random = new Random
Pick at Random
the entry from the array before selecting another name at random
Random Access File.
Random Access File.  Explain Random Access File
using random number
using random number  generate a 10 digit number using random number and display the length of longest increasing series
Random Access File class
Random Access File class  Write a short note on Random Access File class.   Please visit the following link: Java Random Access File
Random data - Java Beginners
Random data  hi friend, I want to ask how to make random data. i has example word like this : Gaza! Gaza! Palestina merdeka! how to make random like : Azag! Azag! Anitselap akedrem! thank's
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  In a random access file, first write the alphabets a,b, c, d till z. Read the file in reverse order and print it on screen
using random number
using random number  generate 10 number and display the length of longest incresing series
using random number
using random number  generate 10 digit number and display the length of longest incresing swries
Numbers
Java NotesNumbers Two kinds of numbers. There are basically two kinds of numbers in Java and most other programming languages: binary integers (most commonly using the type int) and binary floating-point numbers (most commonly using
automorphic numbers
automorphic numbers  how to find automorphic number in java   Hi Friend, Pleas visit the following link: Automorphic numbers Thanks
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program that stores the names of four employees in an array of strings. Store the contents of the array in an alphabetical order in a file and display it back on console. Do not use
Random Creation of password
Random Creation of password  Dear Sir I have created a form with some details in it.When clicking on the submit button it gives me a password... to generate a random password and insert into database... Please help me out
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String...=input.nextInt(); list.add(num); } System.out.println("Numbers
Prime Numbers
Prime Numbers  Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents
random color fill
random color fill   Hi I am trying to create a randomly color filled oval but the outcome is a black filled oval this is the code: package...; Random rcolor = new Random(); int r = rcolor.nextInt(255); int g1
RANDOM ACCESS FILE CONCEPT
RANDOM ACCESS FILE CONCEPT  Write a program to write the details of an employee to a file. Details such as year of joining, department code, employee name and salary should be included. You must use RandomAccessFile
Numbers pyramid
Numbers pyramid  Hi sir, Can you please tell me how to output this using nested for loops? 1 2, 1 1, 2, 3 4, 3, 2, 1 1, 2, 3, 4, 5 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7 8, 7, 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 9, 8

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.