View Single Post
  #4 (permalink)  
Old 05-13-2008, 09:40 AM
Eranga's Avatar
Eranga Eranga is offline
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Best things is make an attempt to do something. Anyway here is a simple code, keep in mind this is not the only way to do this.

Code:
public class ArrayComparing { Scanner console= new Scanner(System.in); String[] names; String[] temp; int[] grade; public static void main(String[] args) { new ArrayComparing().getUserData(); } private void getUserData() { names = new String[3]; for(int i = 0; i < names.length; i++) { System.out.print("Please Enter Student name: "); names[i] =console.nextLine(); temp[i] = names[i]; } grade = new int[3]; for(int i =0;i<grade.length;i++) { System.out.print("Please Enter Student marks: "); grade[i] =console.nextInt(); } sortArray(names); } private void sortArray(String[] arrayToSort) { Arrays.sort(arrayToSort); getIndex(arrayToSort); } private void getIndex(String[] sortedArray) { for(int x = 0; x < sortedArray.length; x++) { for(int y = 0; y < names.length; y++) { if(sortedArray[x].equals(temp[y])) { System.out.println(sortedArray[x] + " " + grade[y]); } } } } }
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote