Description of program: You are to write a program name numbers.java . You are t
ID: 3662315 • Letter: D
Question
Description of program:
You are to write a program name numbers.java. You are to use arrays as your data structure.
Here are some requirements for the program:
c:java -jar numbers.jar [enter]
Enter a number between 1 and 5 for the number of groups of numbers you want to generate. 0
The number must be bewteen 1 and 5. Try again. 6
The number must be between 1 and 5. Try again 4
5 8 19 25 30 7
5 8 19 25 30 17
3 8 19 25 30 17
15 35 43 48 65 15
Would you like to run the program again -- answer y/n or Y/N? n
Good Bye!!
Explanation / Answer
import java.util.*;
class numbers
{
public static void disp()
{
Scanner scan = new Scanner(System.in);
Random rand=new Random();
int max=69, min=1,i,j;
System.out.println("Enter a number between
1 and 5 for the number of groups of numbers you want to
generate.");
int n=scan.nextInt();
int a[][]=new int[5][5];
int b[][]=new int[5][1];
while(true)
{
if(n<1 || n>5)
{
System.out.println
("The number must be bewteen 1 and 5. Try again.");
n=scan.nextInt();
}
else
break;
}
for(i=0;i<n;i++)
{
for(j=0;j<5;j++)
{
a[i][j]= rand.nextInt
((max - min) + 1) + min;
}
}
max=26;
for(i=0;i<n;i++)
{
b[i][0]= rand.nextInt((max - min)
+ 1) + min;
}
for(i=0;i<n;i++)
{
for(j=0;j<5;j++)
{
System.out.print(a[i]
[j]+" ");
}
System.out.println(" "+b[i][0]);
}
}
public static void main(String args[])
{
String ans="y";
Scanner scan = new Scanner(System.in);
while (ans.equals("y"))
{
disp();
System.out.println("Would you
like to run the program again -- answer y/n or Y/N?");
ans=scan.nextLine();
}
}
}