Results 1 to 6 of 6
Thread: Smallest Integer Finder
- 10-31-2012, 06:10 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 15
- Rep Power
- 0
Smallest Integer Finder
This is the code I have so far that I am working on:
What this code does is print out an array of 5 integers with locations and different numbers in the locations. For example when I ran it this is what is printed out.Java Code:public class MixerUpper{ public static void main(String[] args){ int[] myArray = new int[5]; printIntArray(myArray); } public static void printIntArray(int[] myParamVar) { int LOCATION = 0; while(LOCATION<myParamVar.length) { System.out.print("In LOCATION " + LOCATION + " "); System.out.print("Computer has written "); LOCATION = LOCATION + 1; System.out.println(( ( int) ( 4.9999 * Math.random() ) ) ); } return; } }
> run MixerUpper
In LOCATION 0 Computer has written 1
In LOCATION 1 Computer has written 0
In LOCATION 2 Computer has written 4
In LOCATION 3 Computer has written 7
In LOCATION 4 Computer has written 2
>
Now what I need to do is create code so that after it prints out this information. It prints out the smallest integer in the array by first printing its location and then the actual smallest number in the array. (like "Smallest Integer " " in Location " ")
I don't really know where to start on this one as I am very new to programming. Can anyone help out a little?
- 10-31-2012, 09:59 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Smallest Integer Finder
Please do not ask for code as refusal often offends.
- 10-31-2012, 10:44 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 15
- Rep Power
- 0
Re: Smallest Integer Finder
I want to set up code that would be like System.out.println("Smallest integer " //code here to print out smallest integer(no clue here) "in location " //code to find location of that smallest integer here.
Is this even the right aproach?Last edited by antnas; 10-31-2012 at 11:09 PM.
- 11-01-2012, 01:31 AM #4
Re: Smallest Integer Finder
You have 2 issues. First finding the smallest value which has been explained by Tolls above. Second displaying the result which would need a print statement similar to what you post above. So what is your problem? Post your code, error messages and ask a specific question.
- 11-01-2012, 03:54 AM #5
Member
- Join Date
- Oct 2012
- Posts
- 13
- Rep Power
- 0
Re: Smallest Integer Finder
Step number 1 is getting your code to actually set the value of each element in the array. Once you've done that you could actually keep track of what the lowest integer is while you're building your array, rather than doing another loop through in the end. With a few minor tweaks you should have this thing buttoned up.
- 11-01-2012, 04:42 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,540
- Rep Power
- 11
Similar Threads
-
Finding a Smallest Integer
By antnas in forum New To JavaReplies: 3Last Post: 10-26-2012, 04:20 AM -
Path Finder
By OmerHalit in forum AWT / SwingReplies: 2Last Post: 04-05-2010, 08:09 PM -
sign finder
By iPetey in forum New To JavaReplies: 6Last Post: 05-01-2009, 05:24 AM -
Finding largest and smallest integer
By mlhazan in forum New To JavaReplies: 2Last Post: 01-12-2008, 10:30 PM -
Library Finder 1.2
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-15-2007, 04:43 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks