Results 1 to 9 of 9
  1. #1
    gretaks is offline Member
    Join Date
    Sep 2011
    Location
    Karmėlava, Lithuania
    Posts
    25
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need help with basic exercise

    Quote Originally Posted by gretaks View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    299
    Rep Power
    4

    Default Re: Need help with basic exercise

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

  4. #4
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    299
    Rep Power
    4

    Default 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. #5
    gretaks is offline Member
    Join Date
    Sep 2011
    Location
    Karmėlava, Lithuania
    Posts
    25
    Rep Power
    0

    Default 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. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,361
    Blog Entries
    7
    Rep Power
    20

    Default Re: Need help with basic exercise

    Quote Originally Posted by gretaks View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    gretaks is offline Member
    Join Date
    Sep 2011
    Location
    Karmėlava, Lithuania
    Posts
    25
    Rep Power
    0

    Default 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. #8
    gretaks is offline Member
    Join Date
    Sep 2011
    Location
    Karmėlava, Lithuania
    Posts
    25
    Rep Power
    0

    Default 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. #9
    gretaks is offline Member
    Join Date
    Sep 2011
    Location
    Karmėlava, Lithuania
    Posts
    25
    Rep Power
    0

    Default Re: Need help with basic exercise

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

Similar Threads

  1. Have I done this exercise right?
    By ccie007 in forum New To Java
    Replies: 7
    Last Post: 09-28-2010, 05:54 PM
  2. HELP Homework exercise
    By albi_87m in forum Java 2D
    Replies: 3
    Last Post: 04-04-2009, 05:10 AM
  3. String Exercise
    By carlodelmundo in forum New To Java
    Replies: 5
    Last Post: 03-06-2009, 12:59 PM
  4. I/O exercise
    By Feldom in forum New To Java
    Replies: 1
    Last Post: 10-28-2007, 04:48 PM
  5. help with exercise
    By e_as're in forum New To Java
    Replies: 3
    Last Post: 09-25-2007, 10:14 AM

Posting Permissions

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