javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do you get any errors? Place some debug messages and see what happens. The best thing you can do is print the query that you run and try to run at the database.

public static void res(int m1)
{

String dataSourceName = "questions";
String dbURL = "jdbc:odbc:" + dataSourceName;

try { 

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, "",""); 

String query = "INSERT INTO Final " +"(candidate, marks) "+" VALUES "+"(' "+ user +" ' , ' " +m1 +" ' )";

System.out.println("Query:>"+query+"<");

Statement s = con.createStatement();
int i = s.executeUpdate(query); 
System.out.println("Rows updated: "+i);
//ResultSet ps = s.getResultSet();

System.out.println("Is it done??");

}


catch (Exception err)
{
err.printStackTrace();
System.out.println( "Error: " + err.getMessage() );
}

}  // function ends

After you have made those changes to your code, here are your mistakes.
You don't close anything!!!! You must close whatever you open. In order to do that you need to close them in a finally block to make sure that they are always closed:

finally {
   con.close();
   s.close(); // the statement
}

But since those are declared inside the try the above code will not work because they are not visible outside it. Also the close operation also throws an exception so you need to put that in a try-catch as well:

public static void res(int m1)
{

String dataSourceName = "questions";
String dbURL = "jdbc:odbc:" + dataSourceName;

// Declared outside the try so they can be used inside the try and the finally
Connection con = null;
Statement …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you have that js variable, just display it using javascript. No java is involved. Assuming that you call a javascript function that calculates the resolution and you have that javascript variable calculated at the client. Then:

<script>
  function clacRes() {
    // when this function is called at client side you get the resolution

    var res = 100;

    document.getElementById("resolution").value = res;
  }
</script>

<input type="text" name="resolution" id="resolution" value="">

You can make the input to be readonly, or put it in a div tag:

<div id="resolution"></div>

At the above case where you have a div, the javascript would be:

document.getElementById("resolution").innerHTML = res;

Check the tutorials at:http://www.w3schools.com/default.asp

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Forget about the (String [][]) it seems that it doesn't work. Try to do it manually like I suggested:

int rows = myDouble.size(); // number of lines of the file.
finalTemp = new String[rows][];

for (int i=0;i<rows;i++) {
  String[] arr = (String[])myDouble.get(i); // each element of the list is an array
  finalTemp[i] = arr; // the ith element of the finalTemp 2D array is an 1D array
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hmm, I dont have that error, finalTemp = (String [][])myDouble.toArray(); works fine...

Maybe it has something to do java version. After all the toArray is supposed to return a 1D array. Even if each of its elements would be another array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to convert the list to an array after you have read the file. What is it doing inside the while. First read the file and put it into the list. Then outside the while after reading the entire file, convert it into a 2D array. Also if the (String [][]) doesn't seem to work use the second approach:

while ((str = in.readLine()) != null)	//file reading
            {
				str = str.trim();
				temp = str.split(",");
				myDouble.add(temp);
            }

// Now that you have the myDouble convert into an array:
int rows = myDouble.size(); // number of lines of the file.
finalTemp = new String[rows][];

for (int i=0;i<rows;i++) {
 String[] arr = (String[])myDouble.get(i); // each element of the list is an array

 finalTemp[i] = arr; // the ith element of the finalTemp 2D array is an 1D array
}

Remember the finalTemp is a 2D array, the finalTemp is an 1D array, the finalTemp[j] is a String.
Now print the finalTemp array using for loops and see what values it has. Compare them with the data of the file.
Don't continue until you have successfully finished with the file reading. Once you are ok, just for loop the 2D array, convert each of its elements into a number and put that number into an new double array that has the same size as the finalTemp.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After you read the first line of the file, don't add it to the list. It's that simple. Or add that if statement where you add elements to the list.

if (!line.equals("Name Age")) {
  // add to the list
}

And don't compare the list with a String: list.equals("name is age years old") list is not a String. Don't do that. Also the coding is wrong because by the time you reach that point the list has all the elements of the file, so it will never have only this value:
"name is age years old"

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Oh what about parsing it? You did not include the parsing into double part.

It's not that difficult to add this:
Double.parseDouble in the code, wherever you want it to happen.

You can do it after you got the 2D array of before. You can parse the input, create an 1D double array and add that to the list.
With that code given it's up to you to add the parsing. I am not going to do the whole thing, you need to put some of work. If you want double just create a double array parse the values inside it and then continue using those arrays. Do some thinking on your own.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

I was out for awhile. Sorry about that. I tried implementing your code and I get ArrayIndexOutOfBounds on the line that has

age = line[1];

Can this be done w/o using array? I don't think we're supposed to use them for this assignment.

For the ArrayIndexOutOfBoundsException I think you should have used this method:
scan.hasNextLine() instead of scan.hasNext()
But you should wait for apines comment, since it's his code.

For the other bug, try to add some System.out.println where you read the file and add elements to the list in order to see what is read. If the error still remains, just ignore the first line.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

After looking at the code:
In the displayPeopleWithSameAge method, you are comparing the input with the current. But one is a String and the other a PersonNode.
Also you haven't implemented the equals method in the PersonNode class. Try this:

public String displayPeopleWithSameAge(String input) {

for(PersonNode current = head; current != null; current = current.getNext()) {
     if (input.equals(current.getAge())) {
         output += current.toString() + "\n";
     }
   }
   return output;
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can you post some code? The best way to do this is not just print the messages, but save the results of the file in a structure. An array or a list. Then loop the list for the display. When the user enters the age then loop again and print only those with that age.

So, where is your code?

minimi commented: Great help!!!! +1
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Okay I have a problem now. I need to change the way I want it to be.
Firstly, I want to read the text file, then store all my numbers in the text file into a 2D array.
Secondly, after storing them in a 2D array, then I parse them.

May I know how to do that?

Do you mean that the first 2D array will have the values of the file as Strings and then you will loop the array?

In case you have most of the code. I will post part of what you have done with some suggestions. You must remember first that you can add whatever you want in ArrayLists even arrays:

ArrayList fileList = new ArrayList();

BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Serene\\Documents\\Major Project\\Alignment Algorithms\\Testing2.txt")); //reading files in specified directory

 
String line = null;

while ((line = in.readLine()) != null) {
   line = line.trim(); // get rid of trailing spaces: " 1,2,3 " becomes: "1,2,3"
   System.out.println("Line is: "+line); // for debuging

   String [] arr = line.split(","); // now you have an array of {"1","2","3"}

   fileList.add(arr); // the list has all of the arrays
}

// There is a method that converts a list into an array. If the list has values "a", "b", "c" that method will return an array of {"a","b","c"}
// So by using that method you will get an array of arrays, which is a 2D array in java:

String [][] finalArr = (String [][])fileList.toArray();
// each row of …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you submit to the next page read the value of the radio button and query the database based on that number. Then display the data from the DB.

What code did you use to display the radio buttons. I assume that the value of the radio buttons are the number(id) of the account.

<input type="radio" name="radioAccountNo" value="<%=accountNum%>" />

And the above is in a for loop with the name being the same and you change only the value.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

@javaAddict
I stated the approach in my answer.

@apines
That's why my approach checks for the string length instead of immediately access the string at the position.

Ok. I didn't see it in so many posts. I assumed that If someone had given such suggestion it wouldn't be necessary for more posts after yours

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Hasn't anyone thought of using the split method:

String s = "A- 4";
String [] tok = s.split(" ");

// tok[0]: A-
// tok[1]: 4

If you have "B 4" then again you will get an array of two elements.
Then check the length of tok[0]. If it is one then it has only the letter:
tok[0].charAt(0)

If it has length 2 then it also has a +/- :
tok[0] = "A-"
tok[0].charAt(0)
tok[0].charAt(1)


EDIT:
Or even the index of method:

String s = "A 4";
int index = s.indexOf(" ");
String letter = s.subString(0, index); // it might have A+ if the initial string has the symbol +/-
String number = s.subString(index+1, s.length);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Edit: Sorry I didn't look the code and what I wrote was not very accurate. This is the code I suggest:

public class Animal {
   public void eat() { 
      System.out.println("I eat like a generic Animal."); 
   }
 
   public static void main(String[] args) {
   }
}
 
class Fish extends Animal {
   @Override
   public void eat() { 
      System.out.println("I eat like a fish!"); 
   }

  public void eat2() { 
      super.eat();
   }
}
 
class Goldfish extends Fish {
   @Override
   public void eat() { 
      System.out.println("I eat like a goldfish!"); 
   }

   public void eat2() { 
      super.eat2();
   }
}

When GoldFish will call eat2, it will call the super eat2: Fish.eat2. Then Fish.eat2 will call the super eat: Animal.eat.

Try to copy the code and check it out. I didn't test it, but it is up to you to experiment. That is one way to learn.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to look again the whole code: This is wrong, as you know

while () {

}
} // this is an extra bracket

This would work:

if () {
  while () {

  }
}

You need to look the code. Better begin with a new class, and start adding slowly code to it from the previous one, and compile regularly in order to find what you added was wrong.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have a problem with your brackets. After removing some of the code inside the ifs and the whiles, you have something like this:

while () {

} else if () {

}

Which is wrong. Try from the start and this time try to open-close, and then write the code in between.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One simple way is this:

<input type="button" value="Login" name="btnLogIn" onclick="val()" />

And at the val function:

function val(){

        if(document.getElementById("txtAdminId").value.length==0){
            alert("Please Enter Your ID");
        } else if(document.getElementById("txtAdminPassword").value.length==0){
            alert("Please Enter password.");
        } else {
             document.frmAdminLogin.submit();
         }
     }

If you want to have your button to be of type 'submit' then:

<form name="frmAdminLogin" action="AdminLogin" method="post" onsubmit=" call the method here ">

...

<input type="submit" value="Login" name="btnLogIn" />

</form>

If you want the later way the method at the onsubmit event must return true or false. I don't remember if you must enter it like this:
onsubmit="return val();"
OR
onsubmit="val();"

But I do know that val in this case must return boolean

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't believe that you need to put login.java. When you create a servlet it is defined in an xml file where the name of the servlet is set as well as the java class file. So there is a mapping between the servlet name and the class file. Netbeans does that automatically so I believe that if you put action="login" it should work. That is probably the name that NetBeans has given

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post your code. There are various way to do that. If you say that you have javascript that executes then post your code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just declare the classes with the methods described. Then in the first class have your main method and call the other methods. Study how you create classes, declare methods and call them.
You will also need the help of the java API:
java.lang.String

For the second class:

public class LowerCase {
   public static String convertToLowerCase(String input) {
      if (input==null) return "";
      return input.toLowerCase();
   }
}

The 'toLowerCase' method is a method of the String class you can call.

Then in the main method of the first class call it:

String s1 = "ABC";
String s2 = LowerCase.convertToLowerCase(s1);

The names of the classes, methods are random. You can call them anyway you want. Just make sure the class name matches the file name of the class.

Similar you will do the third class with the methods described and the help of the API

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for (int i = 1; i == 60; i = i +1) {

The loop executes as long the condition: i==60 is true. If it is false the loop exits.
So you begin with i=1. Then the condition is checked: i==60 which is false, so the loop exits without doing anything.
You want the loop to executes for i=1,2,3,4,....60. So you want i<=60

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There aren't such problems. Be more descriptive on what you are trying to accomplish

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

have you added the jar to the classpath ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

arrayinput1, arrayinput2 are arrays. You need to loop the arrays and compare their values individually.

Also do you need to compare only 2 character variables or arrays that have many characters?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No it is not inside it. What is done you call FindPiece. You can call it from wherever you want. So you are calling it from inside the method. You can call methods inside other methods:

public void p1() {

}
public void p2() {
  
}
public void p3() {
  p1();
  p2();
}

What is done, the ChessPiece [][] pieces is an array, the pieces[][] is a ChessPiece. So you can call its method:
pieces[row][col].FindPiece(chessPiece)
And since it returns a String then this is a String:
pieces[row][col].FindPiece(chessPiece)
So you can do this:
pieces[row][col].FindPiece(chessPiece).charAt(0)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

@tux4life, uhmm.. right..
can i do that?

ok ok, lack of information, sorry for that...

i'll have to input characters and store it to the character arrays.
i'll have 2 char arrays, so, i will also have 2 input characters...

for example,
the program will ask me to enter the first set of Variables, and the inputs will be stored inside the array. then will ask me to input second set of variables..

Will you know how many characters to enter? If not, you need to have a while loop where the user enters input. When the users enters "quit" for example break from the while.
You can have the Scanner to read the input as a String and if it is not "quit" or if its length is 1 (characters have length 1), concatenate it to a String. Then convert that String to a character array.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Read the input from the keyboard by using the Scanner class. Search for examples. As for the rest you need to provide some more information.
For example, will you have to enter each character after the other or you will need to enter one word and then take that word and put its characters into one char array?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Add a Double object as attribute and when you get it, cast it to Double. Look at the java API for the class: java.lang.Double. It's a class like any other. Don't let its name confuse you. It's a class with methods and attributes.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The session is one. That is what it does. If you had set the attributes to the request then you would be able to access them only from one page to the other. But if you put them to the session, you can access them from any page, no matter how many times you submit or redirect.
There is only one session.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When looping arrays, an array of length: name.length() , has indexes from 0 to name.length()-1.
An array of length 3 has arr[0], arr[1], arr[2], not arr[3]
So the for loop shouldn't be: for (int i = 0; i <= name.length(); i++)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all, have you been told how will you need to read the input?
If it is ok to read the Names separately then you are fine.
If it is required to read once the whole string with the words then you can do what I suggested.
Remember, you can loop the String and get each character with that method. You can use the String.length() method to find the upper limit of the index.

My suggestion was:

"
You might want to loop the String and use the charAt to take each character, using the charAt. Have a new String an initialize it outside the for loop.
In the loop once you find an empty character, means that you have finished with a word so the next character is the first letter of the next word. Concatenate only the next character to the String.
"

If you can use any method to help you then you can use the split method, that will give you the words of the String in an array:

String s = "Dani A. Ona";
String [] tok = s.split(" ");

// tok now is an array with elements:
// tok={"Dani", "A.", "Ona"}

Now you can loop that array and get the first character of each element, but you need to make sure that you are allowed to use that method. Maybe not if you said that you can use only the charAt.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

@javaaddict, yes i ran the program...and its alright.
i have a question...
if i will input my name once, not in separate ones...
if i will use the if statement, then my program can read the first letter, but how can my program read the rest of my initials, and output them?

@Akill, yes i got the code from the net
then the program you said, i wrote it.. :)
i do not... copy and paste :)

You mean if you have a String like this: "aaa bbb cc" how can you get the initials?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I didn't know that the user could enter the names separately. It is much easier that way. Have you tried running the program?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

charAt is a method of the String class. In case you don't know it:

String s = "abs";
char ch = s.charAt(0);
System.out.println(ch);

You might want to loop the String and use the charAt to take each character, using the charAt. Have a new String an initialize it outside the for loop.
In the loop once you find an empty character, means that you have finished with a word so the next character is the first letter of the next word. Concatenate only the next character to the String.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your query is wrong. Do some studying about sql. If you want to use ? and prepared statements don't use quotes. Use this:

"Select * from pin_numbers where pin_number like ?"

pst.setString(1,pin);

If you want to search rows that have this: "twt000" inside their value, then this '*' will not work with sql.
Use:

"Select * from pin_numbers where pin_number like '%" + pinnumber + "%'";

Not prepared statement.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

what else do you have in that jsp ?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Do have the JAVA_HOME environment variable set. After doing some searching, and now I remember that I had the same problem, I found that you have to put first the latest java version that you are using when declaring that variable. You must also set your classpath correctly in order to use the latest java version when compiling and running

After very little search, I found this page:
http://www.devdaily.com/blog/post/java/java-lang-unsupportedclassversionerror/

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post some code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It is obviously that even the %d that you use is correct, the %lf is not.
Try to use this: %f.
And check this link for more information:
http://download.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The code works for me. Does the message display correctly? ("there is a value")
Can you post an image of the gui that you see.
Also is the image file at the correct path. ("image.jpg") . Have you tried the full path?
Also have you tried setting the size of the frame? frame.setSize(400, 400); Also just because the icon is not null, doesn't mean that the image file exists. Whatever you put as file, the instance would be created and it would be not null even if the image does not exist

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For writing I use this:
BufferedWriter, FileWriter:

BufferedWriter wr = null;
try {
   wr = new BufferedWriter(new FileWriter("Exercise09_19.txt"));

   wr.write("something");
} catch (Exception e) {
  System.out.println(e.getMessage());
} finally {
  if (wr!=null) wr.close();
}

The BufferedWriter is declared outside the try, in order to be "visible" in the finally when we close it. But initialized in the try because it throws an exception. Since the close also throws an exception, you should try this:

BufferedWriter wr = null;
try {
   wr = new BufferedWriter(new FileWriter("Exercise09_19.txt"));

   wr.write("something");
} catch (Exception e) {
  System.out.println(e.getMessage());
} finally {
  try {if (wr!=null) wr.close();} catch (Exception e) {}
}

Write to the file and then review it. I would suggest to put wr.write("something") in your loop. Meaning that all your loop would be in the try - catch.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would have done this:

<img src="images/bus.jpg" id="ck" alt="" width="40" height="40" name="imgChange" onclick="changeImage();">
function changeImage() {
  if (document.getElementById("ck").src=='images/bus.jpg') {
    document.getElementById("ck").src = 'images/nice.jpg';
  } else if (document.getElementById("ck").src=='images/nice.jpg') {
    document.getElementById("ck").src = 'images/bus.jpg';
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have to "connect" the objects: BookList and UserList. Either add an attirubte to one of those to be the other. Add to the BookList an UserList attribute.

book.setAvailable(resultSet.getBoolean("available"));
appliedUser.setId(resultSet.getLong("user_id"));

book.setAppliedUser(appliedUser);

bookList.add(book);

Or create a new class that has those 2 as attribute and return that class.

In the first case the code would look like that:

public ArrayList<BookList> getAppliedBooks(UserList user){
...

    ArrayList<BookList> bookList = new ArrayList<BookList>();

    try {

...

        BookList book;
        UserList appliedUser;
        while (resultSet.next()) {
            book= new BookList();
            appliedUser = new UserList();

...

            book.setAvailable(resultSet.getBoolean("available"));
            appliedUser.setId(resultSet.getLong("user_id"));

            book.setAppliedUser(appliedUser);

            bookList.add(book);
        }
        
    }
    catch(Exception e){

        e.printStackTrace();
    }

    finally {
        if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {}
        if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {}
        if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}
    }

    return bookList;
    }
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know your logic, but what if you try this:

class MultiThreader {

    main(...) {

 
       new MultiThreader().jobSpawner(jobName);
    }

    void jobSpawner(String jobName) {
        new Thread(new JobThread(this, jobName)).start(); // use 'this' here
    }

}

In this case the 'this' would reference the instance that is created in the main:
new MultiThreader().jobSpawner(jobName)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
new MultiThreader().jobSpawner(this, jobName);

'this' is a key word that can be used in a class only by its class members and it used to call class variables and methods:

private int a = 0;

public void setA(int a) {
  System.out.println(this.a); // it will print the value of the 'a' class variable
  System.out.println(a); // it will print the argument.

  this.a = a; // it will set the value of the class variable to be the argument
}

You cannot use the 'this' in a static method like the static void main()

In the main method you need to pass a instance of that class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well the error says that Password is not ASCII. So maybe if you could print the values of the password array one by one and see what it has.
Perhaps the problem is that the last element of the array is the \n new line.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes JSP, it can be done with jsp, but do you know java? Because you can not write jsp, and especially such project without knowing good java.

Check the tutorials at the top of the java and the jsp forum.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes, after the loop.

First of all if you do it in the loop, the array starts like this: {0,0,0,...
Then you put the 0th element: {3,0,0,.. If you sort that 3 will go at the end of the array.
So after the sort you have: {0,0,0,......,3}. Then you will put the 1th element at the i position: {0,5,0,... If you do that you are stuck with a zero at the 0th position. Nothing will change that because you keep adding elements at the 2nd, 3rd. That zero and the other zeros are there to stay.

Also if you do the sorting in the loop you will be calling that method 100 times. Why call the sort 100 times, when you can call it once after you have the array ready.

Also the array has been sorted. There is no doubt about that. But you don't save the sorted array in the file:

for () {
  get random number;
  write to file (unsorted);
}
sort array;

The numbers saved to the file are unsorted, but the array is.

Now what do you want?
Do you want to sort the array? Do you want to save the unsorted array? Do you want to save the sorted array? Do you want to save both?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think I can assume what the problem is. Do you do the sorting in the for loop? If yes here is what happens.

for () {
  number[i] = random;
  sort;
}

First of all when you create the array all of its elements are zero.
When you sort you rearrange the elements of the array. So when you try to add the second random number it is being put at the second position of the sorted array, not after the previous number.

Array = {0,0,0,0,0}
Adding number = {5,0,0,0,0} // i = 0
Sorting = {0,0,0,0,5}

Array = {0,0,0,0,5}
Adding number = {0,2,0,0,5} // i = 1
Sorting = {0,0,0,2,5}

Array = {0,0,0,2,5}
Adding number = {0,0,4,2,5} // i = 2
Sorting = {0,0,2,4,5}

If you keep this up, the initial values you entered will be overridden by the new ones you added:

Array = {0,0,2,4,5} // adding the next number at the i=3
Adding number = {0,0,2,8,5} // i = 3 // the 4 is gone
Sorting = {0,0,2,8,5} // and the zeros are still there


Array = {0,0,2,8,5} // adding the next number at the i=4
Adding number = {0,0,2,8,1} // i = 4 // the 5 is gone
Sorting = {0,0,1,2,8} // and the zeros are still there