Sample Java code that shows how to use arrays and list the contents of an array in order.

Posted: September 4, 2013. At: 11:58 AM. This was 4 years ago. Post ID: 6206
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

This Java code displays a list of students and their scores and also displays a list of their names in alphabetical order.

Use this command to compile this: gcj --main=Employees Employees.java -o hello.

/*
 * My first Java program.
 *
 */
 
import java.util.Arrays;
 
public class Employees {
 
	public static void main(String[] args) {
 
		String[] myStringArray = new String[]{"Rodney","Daniel","Bavita", "Peter", "Imran", "Lobosh", "Yuting", "Carl"};
		int[] myIntArray = new int[]{333,221,401,297,116,250,354,134};
 
		System.out.printf("\nSorted list of names.\n");
 
		/* args is the list of Employees. */
 
		Arrays.sort(myStringArray);
 
		for(int i = 0; i < myStringArray.length; i++) {
			System.out.println(myStringArray[i]);
		}
 
		System.out.printf("\nEnd of sorted list.\n");
 
		for(int j=0; j< 8; j++ ) {
 
			System.out.printf("\nScore: " + myStringArray[j] + ", " + myIntArray[j] + ".\n");
		}
	}
}

No comments have been made. Use this form to start the conversation :)

Leave a Reply