# Need help with basic exercise

• 09-10-2011, 08:02 PM
gretaks
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)
• 09-10-2011, 08:07 PM
JosAH
Re: Need help with basic exercise
Quote:

Originally Posted by gretaks
it come to me like this:
run:
****** Lab1 ******
[I@1fee6fc
[I@1eed786
8
BUILD SUCCESSFUL (total time: 0 seconds)

First line have to show my array but showing numbers and letters i don;t know where i made a mistake.

You didn't make a mistake; that's the way arrays show themselves; they're kind of stupid. Read the API for the toString( ... ) methods in the Arrays class to show those dumb arrays in a more decent way.

kind regards,

Jos
• 09-10-2011, 08:08 PM
milovan
Re: Need help with basic exercise
Are you trying to print 4, 2, 5, 3, 8?
• 09-10-2011, 08:29 PM
milovan
Re: Need help with basic exercise
If you could edit your post with [CODE] tags it would be much easier to find problem
• 09-10-2011, 08:34 PM
gretaks
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
JosAH
Re: Need help with basic exercise
Quote:

Originally Posted by gretaks
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.. :?

It's not that line; in the next lines you set each and every element to the value 'val', that's why you see ten identical values ...

kind regards,

Jos
• 09-10-2011, 08:50 PM
gretaks
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
gretaks
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
gretaks
Re: Need help with basic exercise
its something wrong with secon array it would be third line..