Results 1 to 9 of 9
Thread: Need help with basic exercise
- 09-10-2011, 08:02 PM #1
Member
- Join Date
- Sep 2011
- Location
- Karmėlava, Lithuania
- Posts
- 25
- Rep Power
- 0
Need help with basic exercise
There are a few numbers array. Shape into a new array of numbers which are larger than the first number, the data array. Both the maximum number of blocks in the search for and compare with each other. Print the original array, formed by an array and compare the results.
package lab1;
public class Klase1 {
public void metodoParinkimas(){
System.out.println("****** Lab1 ******");
int[] mas1={4, 2, 5, 3, 8};
int[] mas2= new int[10];
int l=mas1.length;
for(int i =0;i<l;i++)
System.out.print(" "+mas1[i]);
System.out.print("\n");
met1Masyvas1(mas1,mas2);
int n=met1Masyvas1(mas1,mas2);
for(int i=0;i<10;i++)
mas2[i]=n;
System.out.println(n);
for(int i=0;i<10;i++)
System.out.print(" "+mas2[i]);
}
public static int met1Masyvas1(int[] masa, int[] masb){
int k=0;
for(int i=0;i<masa.length;i++)
if(masa[0]<masa[i]){
masb[k]=masa[i];
k++;
}
return masb[k];
}
}
run:
****** Lab1 ******
4 2 5 3 8
0
0 0 0 0 0 0 0 0 0 0
BUILD SUCCESSFUL (total time: 0 seconds)Last edited by gretaks; 09-12-2011 at 06:47 PM.
- 09-10-2011, 08:07 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
Re: Need help with basic exercise
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-10-2011, 08:08 PM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Re: Need help with basic exercise
Are you trying to print 4, 2, 5, 3, 8?
- 09-10-2011, 08:29 PM #4
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
Re: Need help with basic exercise
If you could edit your post with [CODE] tags it would be much easier to find problem
Last edited by milovan; 09-10-2011 at 08:35 PM.
- 09-10-2011, 08:34 PM #5
Member
- Join Date
- Sep 2011
- Location
- Karmėlava, Lithuania
- Posts
- 25
- Rep Power
- 0
Re: Need help with basic exercise
now its ok?
i think problem is with this : int[] mas2= new int[10];
thats why 10times writing 8.
but i need that into a new array program will write 5 8 only not 8 ten times.. :?
- 09-10-2011, 08:44 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 09-10-2011, 08:50 PM #7
Member
- Join Date
- Sep 2011
- Location
- Karmėlava, Lithuania
- Posts
- 25
- Rep Power
- 0
Re: Need help with basic exercise
how to write it correct?
because i thougth that 'val' is like in first method finds bigger number than first, and writes in mas2[0]=5 and then mas2[1]=8 :/
i don;t know how to fix it :/
- 09-10-2011, 09:35 PM #8
Member
- Join Date
- Sep 2011
- Location
- Karmėlava, Lithuania
- Posts
- 25
- Rep Power
- 0
Re: Need help with basic exercise
if I will write like this:
public void met2Masyvas2(int[] val){
mas2[k]=val[i];
then its shows a mistake in here:
int n=met1Masyvas1(mas1);
met2Masyvas2(n);
because n is int nor a int[]; i cant change it in first method i think.. :/
- 09-12-2011, 06:48 PM #9
Member
- Join Date
- Sep 2011
- Location
- Karmėlava, Lithuania
- Posts
- 25
- Rep Power
- 0
Similar Threads
-
Have I done this exercise right?
By ccie007 in forum New To JavaReplies: 7Last Post: 09-28-2010, 05:54 PM -
HELP Homework exercise
By albi_87m in forum Java 2DReplies: 3Last Post: 04-04-2009, 05:10 AM -
String Exercise
By carlodelmundo in forum New To JavaReplies: 5Last Post: 03-06-2009, 12:59 PM -
I/O exercise
By Feldom in forum New To JavaReplies: 1Last Post: 10-28-2007, 04:48 PM -
help with exercise
By e_as're in forum New To JavaReplies: 3Last Post: 09-25-2007, 10:14 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks