Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Hello I'm new to java i need help

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Hello I'm new to java i need help

    Implement a function that composes a new list of numbers consisting of elements of two passed lists arranged in ascending order, for example: (( 3, 9, 2, 73, 8, 3, 5 )) - ( 2, 3, 3, 5, 7, 8, 9)

    Implement as a function

    public static List cinteger > createNewList(List integer) list1, List<Integer> list2)


    Do not change the transferred lists. For convenience to implement additional functions:
    public static int copy(

    List, integer> src. // list from which items are copied

    int srcIndex, // position which copied from the src

    List<Integer> dst // list which the elements copied in.

    int dstIndex. // position from which elements are copied in dst

    int count // number of copied elements

    public static void sort(ListcInteger) list)

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hello I'm new to java i need help

    What have you tried?
    Be sure to wrap any posted code in code tags.

    Do you have any specific java programming questions about your assignment?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hello I'm new to java i need help

    Quote Originally Posted by Norm View Post
    What have you tried?
    Be sure to wrap any posted code in code tags.

    Do you have any specific java programming questions about your assignment?
    --_____
    This code solve it but its not the right methods
    And I don't know any thing about Lists functions
    import java.util.*;

    class Program {

    *** public static void sortedMerge(int a[], int b[], int res[], int n, int m)

    *** {

    ******* Arrays.sort(a);

    ******* Arrays.sort(b);

    ******* int i = 0, j = 0, k = 0;

    ******* while (i < n && j < m) {

    *********** if (a[i] <= b[j]) {

    *************** res[k] = a[i];

    *************** i += 1;

    *************** k += 1;

    *********** } else {

    *************** res[k] = b[j];

    *************** j += 1;

    *************** k += 1;

    *********** }

    ******* }****

    *********

    ******* while (i < n) {
    *********** res[k] = a[i];

    *********** i += 1;

    *********** k += 1;

    ******* }****

    ******* while (j < m) {*
    *********** res[k] = b[j];

    *********** j += 1;

    *********** k += 1;

    ******* }

    *** }
    *** public static void main(String[] args)*

    *** {

    ******* int a[] = { 3, 9, 2, 7};

    ******* int b[] = { 8, 3, 5 };

    ******* int n = a.length;

    ******* int m = b.length;

    ******* int res[] = new int[n + m];

    ******* sortedMerge(a, b, res, n, m);

    ******* System.out.print( "Sorted merged list :");

    ******* for (int i = 0; i < n + m; i++)

    *********** System.out.print(" " + res[i]);***

    *** }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hello I'm new to java i need help

    Please post clean code without the leading ***s.
    Be sure to wrap with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Look at the tutorial: https://docs.oracle.com/javase/tutor...ents/list.html
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hello I'm new to java i need help

    import java.util.*;
     
    class Program { 
     
    public static void sortedMerge(int a[], int b[], int res[], int n, int m) 
     
     { 
     
    Arrays.sort(a); 
    Arrays.sort(b); 
     
    int i = 0, j = 0, k = 0; 
     
     while (i < n && j < m) { 
     if (a[i] <= b[j]) { 
     
    res[k] = a[i]; 
     
     i += 1; 
     
    k += 1; 
    } else { 
     
    res[k] = b[j]; 
     
     j += 1; 
     
     k += 1; 
     
     } 
     
     }
     
    while (i < n) { 
     res[k] = a[i]; 
    i += 1; 
     
     k += 1; 
     
    } 
     
    while (j < m) {
    res[k] = b[j]; 
     
    j += 1; 
     
    k += 1; 
     
     } 
     
    } 
    public static void main(String[] args)
    { 
     
    int a[] = { 3, 9, 2, 7}; 
     
     int b[] = { 8, 3, 5 }; 
     
    int n = a.length; 
     
     int m = b.length;
     
     int res[] = new int[n + m]; 
     
    sortedMerge(a, b, res, n, m);
     System.out.print( "Sorted merged list :"); 
     
    for (int i = 0; i < n + m; i++) 
     
     System.out.print(" " + res[i]);
    } 
    }
    Last edited by Yashar.deeb; December 12th, 2019 at 11:12 AM.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Hello I'm new to java i need help

    Please post clean code without the leading ***s.

    Now the code's indentations need fixing. Not all statements should start in the first column of the line.

    Also there are too many blank lines that make the code harder to read.


    What questions or problems do you have about the posted code?
    If you don't understand my answer, don't ignore it, ask a question.

Tags for this Thread