# Thread: Need help with basic exercise

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.

2. ## Re: Need help with basic exercise

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

3. Senior Member
Join Date
Jan 2011
Location
Posts
311
Rep Power
6

## Re: Need help with basic exercise

Are you trying to print 4, 2, 5, 3, 8?

4. Senior Member
Join Date
Jan 2011
Location
Posts
311
Rep Power
6

## 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.

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.. :?

6. ## Re: Need help with basic exercise

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

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 :/

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.. :/

9. Member
Join Date
Sep 2011
Location
Karmėlava, Lithuania
Posts
25
Rep Power
0

## Re: Need help with basic exercise

its something wrong with secon array it would be third line..

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•