Bookmark Topic Watch Topic
  • New Topic

Please help me to correct my code. I dont know how to get return value and print it out  RSS feed

 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Report post to moderator
here is my code.
i have errors on line 7, 8
[code]public class Merging {
    public static void main(String[] args) {
       
        int[] a_array = {5,9,11,15,20};
        int[] b_array = {2,3,6,7,12,13,16,19,21};
       
        for(int number : merge(c_array)) {
            System.out.println(number);
         }
}
    public static int[] merge(int[] a_array, int[] b_array) {

    int[] c_array = new int[a_array.length + b_array.length];
    int i = 0, j = 0, k = 0;

    while (i < a_array.length && j < b_array.length)
    {
        if (a_array[i] < b_array[j]){
            c_array[k] = a_array[i];
            i++;
        }
        else {
            c_array[k] = b_array[j];
            j++;
        }
        k++;
    }
    while (i < a_array.length)
        c_array[k++] = a_array[i++];

    while (j < b_array.length)
        c_array[k++] = b_array[j++];
   
    return c_array;
    }
}
[code]
 
Ganesh Patekar
Bartender
Posts: 696
23
Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Oracle Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Report post to moderator
I think you created separate topic just to add code tags Or to change topic title. As Greenhorn I know you can't edit once posted, you can wait for a staff member to notice It, once they notice code without code tags they will notify and permit you to edit that post.

About topic title I think you can edit that ( Although not you can ask staff on the same topic to edit title). So please don't create multiple topics for the same question as you now know the alternative options. Please continue discussion over here https://coderanch.com/t/670508/java/java/return-function#3133157
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!