So I tried to write a program that creates 15 random strings then allows the user whether he wants these strings sorted in descending or ascending order. the original strings and the sorted one to be displayed accordingly as well. Here is my attempt:

class Sorted strings{

final static int MAXSTR = 15;             // number of random strings
final static int STRLEN = 8;                 // maximum string length

public static void main(String[] args){
           String strs[] =  new String[MAXSTR];
           String sort[] = new String[MAXSTR];
           boolean more, ascend;
Int i, el, j;

for (i=0; i<MAXSTR; i++){
strs[i] = "";                                             // initialise string to blank
for (j=0; j<STRLEN; j++){
el = (int)((Math.random()*100000))%125;
strs[i] = strs[i]+(char)(el);           // add random symbol

title();              //title + instructions

copy(strs, sort);            //copy random strings to “sorted” string array


//ascending or descending
ascend = get_ascend_or_descend();

//display Unsorted data

//display SORTED data
displaysort(strs, sort);

more = kdr.goagain();                //makes the user want to repeat

//copies one string array to another
static void copy(String original[], String newest[]){
int zz;

for (zz=0; zz<original.length; zz++)
newest[zz] = original[zz];

//procedure to display sorted data
static void displaysort(String sn[], String srt[]){
int loop;

System.out.print("Original Sorted\n\n");
for(loop = 0; loop<sn.length; loop++){

// finds out if the user wants to sort ascending or descending
Static boolean gets_ascend_or_descend(){
         Char asds;

         System.out.print (“\n\nDo you wish to sort <A>scending or <D>escending :”);
asds = Keyboard.readChar();
asds = Character.toLowerCase(asds);
}while(asds!=’a’ && asds!=’d’);
if (asds == ‘d’)

// title page
static void little(){
System.out.print(“\n\nThe program will create 30 random strings. You”);
System.out.print(“\nwill then be asked whether you want to sort ascending”);
System.out.print(“\nor descending. The program will then display the”);
System.out.print(“\noriginal strings and sorted ones. \n\n\n\n\n\n”);

I made comments throughout the program. However when I compiled it I got tons of errors :( Help please.

Edited 5 Years Ago by masijade: added code tags but the indentation is crappy anyway

It might help to know what errors. I am not going to play compiler and even try to figure them out when you could just post them. And fix your indentation, how do you expect anyone to be able to read that properly?

Yeah I'm sorry about not tagging it mate a bit new here. Here is the error I'm getting that I can't get to understand why.

The first line where it says

class Sorted strings{

it tells me:

'{' expected

but I already have it.

That line should be structured

[access modifier] class <classname> [extends <classname>] [implements <interfacename>] {

where does "strings" fit into that?

Edited 5 Years Ago by masijade: n/a

This article has been dead for over six months. Start a new discussion instead.