Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 18th, 2006, 10:33 PM   #1
Alache
Newbie
 
Join Date: Apr 2006
Posts: 2
Rep Power: 0 Alache is on a distinguished road
Java arrays - help!

Hi, I'm having some trouble with a java assignment. Can someone help me out plz: emergency!
here's the problem:

[i]Write a program that reads numbers from the keyboard into an array of type int[]. You may assume that there will be 50 or fewer entries in the array. Your program allows any number of numbers to be entered up to 50 numbers. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of eahe element. The list should be sorted on entries in the first column, largest to smallest.

thanks!
Alache is offline   Reply With Quote
Old Apr 18th, 2006, 10:41 PM   #2
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
What have you got so far?
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Apr 18th, 2006, 10:43 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4 Jessehk is on a distinguished road
Please attempt to atleast produce a general idea of what to do (psuedo-code) to solve the problem.

People will not take their time to do your homework, despite what you may think.

If you have a specific question about the assignment, then perhaps an individual will be more inclined to help you out.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Apr 19th, 2006, 12:35 AM   #4
Alache
Newbie
 
Join Date: Apr 2006
Posts: 2
Rep Power: 0 Alache is on a distinguished road
Sorry for not being precise enough; this is what i got so far; i plan to do the main method last, I did the input method, but i'm stuck on the creation of the list.

import java.util.Scanner;
public class ArrayProg 
{
	public static final int Max_Entries = 50;
	private static int[] entries = new int[Max_Entries];
	
	public static void main (String[] args)
	{
		
	}
	public static int fillArray()
	{
		System.out.print("Enter up to " + entries.length + " non decimal number: ");
		Scanner keyboard = new Scanner(System.in);
		int index = 0;
		int next = keyboard.nextInt();
		while (index < entries.length)
		{
			
			entries [index] = next;
			index++;
			next = keyboard.nextInt();
		}
	return index;
	}
	public static int createList()
	{
		
	}
}

Last edited by Mjordan2nd; Apr 19th, 2006 at 12:36 AM. Reason: Code Tags
Alache is offline   Reply With Quote
Old Apr 19th, 2006, 12:44 AM   #5
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Please use code-tags next time.

Also, what I would do is have a method like this:

public static void method()
{
	 for(int i = 0; i<entries.length; i++)
	 {
		  // if entries[i] = any of the elements before it then 
				 //continue
		  int counter = 1;
		  for(int j = i; k<entries.length; j++)
		  {
				// if entries[j] is the same as entries[i] add 1 to counter
		  }
		  // print entries[i] and then counter
	 }
}


That would be the way I'd go.
__________________
&quot;Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children.&quot; - Dwight D. Eisenhower

Last edited by Mjordan2nd; Apr 19th, 2006 at 7:55 AM.
Mjordan2nd is offline   Reply With Quote
Old Apr 19th, 2006, 2:11 AM   #6
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Good point MJ, I was going to suggest the same but then I read your post and it looks like you got it under control.

"for" loops are better for assigning arrays their values in a consecutive way.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC