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");		
	    	}
	    }	
	}
}

Recommended Answers

All 5 Replies

Please use code tags around your code to preserve formatting, and.... what is the question?

i have to make a code that will create, draw, ask the user to add new values, and sort the array by making a menu to help choose which part to do.

Ok, so again, what is your question?

Ok, so again, what is your question?

how to get the program to run, bc i dont know how to make it prints the array and i dont know how to add new values into the array?

how to get the program to run

If you don't know how to run the program it is better to do some tutorials before doing this, I think. Isn't it?

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.