import java.util.*;
public class Prj3
{
static int data[] = new int[20];
static Scanner kb = new Scanner(System.in);
static Random rnd = new Random( 1234 );
static void Create_array(int arr[], int max)
{
int i;
for (i=0; i<100; i++)
arr[i] = rnd.nextInt(max);
}
static void Draw_array(int arr[], int col)
{
int i;
for (i=0; i<20; i++)
{
if (i % col == 0 && i != 0)
System.out.printf("\n");
System.out.printf("%4d", arr[i]);
}
System.out.printf("\n\n");
}
static void New_value()
{
}
static void Sort_array(char order)
{
int i, j, tmp;
for (i=0; i<100; i++)
{
for (j=i+1; j<100; j++)
{
if (order == 'D' || order == 'd')
{
if ( data[i] < data[j])
{
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
}
if (order == 'A' || order == 'a')
{
if ( data[i] > data[j])
{
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
}
}
}
}
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int a;
String str;
boolean bl=true;
int data[] = new int[20];
while (bl)
{
System.out.printf("\n1. Create a random array");
System.out.printf("\n2. Draw array");
System.out.printf("\n3. Enter new values");
System.out.printf("\n4. Sort the array");
System.out.printf("\n5. Exit");
System.out.printf("\n\nPlease make a Selection: ");
a = kb.nextInt();
//Draw a menu and get a valid choice
switch (a)
{
case 1: System.out.printf("\n\nCreates a random array\n");
Create_array(data, 20);
Draw_array(data, 10);
break;
case 2: System.out.printf("\n\nDraw an array\n");
break;
case 3: System.out.printf("\n\nEnter new values\n");
break;
case 4: System.out.printf("\n\nSort the array\n");
break;
case 5: System.out.printf("\n\nExit\n");
bl = false;
break;
default: System.out.printf("\n\nInvalid");
}
}
}
}
nuch1311 0 Newbie Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
nuch1311 0 Newbie Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
nuch1311 0 Newbie Poster
eranga262154 22 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.