getting errors

Ads
 

getting errors

public

class positive {

public static void main(String[] args) {

retainPositiveNumbers(a);

}

private

static int n;

private

static int j;

static

int a[]={-1,2,3,4,-5};

static

int c[]={};

public static int[] retainPositiveNumbers(int[] a) {

/*

Please implement this method to

return a new array with only positive numbers from the given array.

The elements in the resulting array shall be sorted in the ascending order.

*/

?

for(int i=0; i<a.length; i++)

{

j=0;

if(a[i]>0)

{

c[j]=a[i];

j++;

}

}

for(int k=0;k<c.length;k++){

System.out.println(c);

}

return c ;

}

}
View Answers

April 27, 2012 at 4:35 PM

This example finds the positive integers from the given array and store these positive integers in another array.

import java.util.*;

public class positive {

public static void main(String[] args) {
int a[]={-1,2,3,4,-5};
retainPositiveNumbers(a);
}
public static void retainPositiveNumbers(int[] a) {
    List<Integer> list=new ArrayList<Integer>();
    for(int i=0; i<a.length;i++){
        if(a[i]>0){
         list.add(new Integer(a[i]));
        }
    }
    int[] c = new int[list.size()];
    for (int i=0; i < c.length; i++){
        c[i] = list.get(i).intValue();
    }
     for (int i=0; i < c.length; i++){
     System.out.println(c[i]);
    }
  }
}

Ads









Related Tutorials/Questions & Answers:
getting errors
getting errors  public class positive { public static void main(String[] args) { retainPositiveNumbers(a); } private static int n; private static int j; static int a[]={-1,2,3,4,-5}; static int
errors
that what the errors in above code
Advertisements
Compiler errors in java
Compiler errors in java  Hi, I used GenerateRDF java file. Am getting errors when i run this code. I used command prompt only. getting errors as no package exist. i followed your instructions properly. Please help me out
What is the errors?
What is the errors?  ) while ( c <= 5 ) { product *= c; ++c;   if ( gender == 1 ) cout << "Woman" << endl; else; cout << "Man" << endl;   Post the whole code
compilation errors
() { } } giving errors: 1) WelcomeServlet.java:37: ')' expected
types of errors in php
types of errors in php  What are the different types of errors in php
Java Program Errors
Java Program Errors  These are the 2 errors which I am getting when executing the java source code extracted from executable jar file The project was not built since its build path is incomplete. Cannot find the class file
ModuleNotFoundError: No module named 'errors'
ModuleNotFoundError: No module named 'errors'  Hi, My Python... 'errors' How to remove the ModuleNotFoundError: No module named 'errors'... to install padas library. You can install errors python with following command
The errors tag
In this section, you will learn about the errors tag of the Spring form tag library
STRUTS2.0 Validation Errors
the previous field errors persist in the page. For eg:if i am not entering both... message("username is required") is not getting removed.It still shows both
selectoptions errors in java script
selectoptions errors in java script  hi, in my web page when I select the color of the image it displays that particular color but when i again opt the select option it displays errors message. How do I rectify this problem
Servlets errors in same page.
Servlets errors in same page.  How do I display errors list in the same page where a form field exists using servlets...........i.e. without using JSP? Please explain with a simple username password program
ModuleNotFoundError: No module named 'django-errors'
ModuleNotFoundError: No module named 'django-errors'  Hi, My... 'django-errors' How to remove the ModuleNotFoundError: No module named 'django-errors' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'edeposit.amqp_errors'
ModuleNotFoundError: No module named 'edeposit.amqp_errors'  Hi...: No module named 'edeposit.amqp_errors' How to remove the ModuleNotFoundError: No module named 'edeposit.amqp_errors' error? Thanks   Hi
ModuleNotFoundError: No module named 'haiku-errors'
ModuleNotFoundError: No module named 'haiku-errors'  Hi, My Python... 'haiku-errors' How to remove the ModuleNotFoundError: No module named 'haiku-errors' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'masonite-errors'
ModuleNotFoundError: No module named 'masonite-errors'  Hi, My... named 'masonite-errors' How to remove the ModuleNotFoundError: No module named 'masonite-errors' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pretty-errors'
ModuleNotFoundError: No module named 'pretty-errors'  Hi, My... 'pretty-errors' How to remove the ModuleNotFoundError: No module named 'pretty-errors' error? Thanks   Hi, In your python
Java errors when attempting the following.
Java errors when attempting the following.  Give the java errors in attempting the following : 1) performing division operation on string value. 2) redefining base class final method in derived class. 3) defining a method
Need urgent help with C++ errors!
Need urgent help with C++ errors!  hi, i'm new to C++ programming. this is my code... i'm using Turbo C++. It's showing so many errors!.. I...() { cout<<"Can somebody fix this?"; } the errors are listed as follows
getting the emplo
getting the emplo   I have one table "EMPLOYEEMASTER" contains 'emp id', 'employee name' for eg: emp id employee name... kumar i want the sql statement for getting like emp id
Getting an error :(
Getting an error :(  I implemented the same code as above.. But getting this error in console... Console Oct 5, 2012 10:18:14 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server
getting voucherPin
getting voucherPin  I am doin an online credit topup application..and i need a method to fetch and decrypt the voucherpin from Database.. this is my voucher repository Class. public interface VoucherRepository extends
remopving errors incore java programming
remopving errors incore java programming  sir error in program:-file does not contain class runnable program:- class MyRunnable implements Runnable{ public void run(){ System.out.println("Run"); } public
remopving errors incore java programming
remopving errors incore java programming  sir error in program:-file does not contain class runnable program:- class MyRunnable implements Runnable{ public void run(){ System.out.println("Run"); } public
remopving errors incore java programming
remopving errors incore java programming  sir error in program:-file does not contain class runnable program:- class MyRunnable implements Runnable{ public void run(){ System.out.println("Run"); } public
need to fix errors please help
need to fix errors please help  it does have 2 errors what should i fix? import java.io.*; class InputName static InputStreamReader reader = new InputStreamReader(system.in); static BufferedReader input = new BufferedReader
Runtime Errors
Runtime Errors          Errors are arised when there is any logic problem with the logic of the program.  In this program we are trying
ModuleNotFoundError: No module named 'cf-pretty-form-errors'
ModuleNotFoundError: No module named 'cf-pretty-form-errors'  Hi...: No module named 'cf-pretty-form-errors' How to remove the ModuleNotFoundError: No module named 'cf-pretty-form-errors' error? Thanks   Hi
ModuleNotFoundError: No module named 'datasette-show-errors'
ModuleNotFoundError: No module named 'datasette-show-errors'  Hi...: No module named 'datasette-show-errors' How to remove the ModuleNotFoundError: No module named 'datasette-show-errors' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-client-errors'
ModuleNotFoundError: No module named 'django-client-errors'  Hi...: No module named 'django-client-errors' How to remove the ModuleNotFoundError: No module named 'django-client-errors' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-client-errors'
ModuleNotFoundError: No module named 'django-client-errors'  Hi...: No module named 'django-client-errors' How to remove the ModuleNotFoundError: No module named 'django-client-errors' error? Thanks   Hi

Ads