Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


syam madala
getting errors
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners


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 ;

}

}

Advertisement
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]);
    }
  }
}


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
Getting 404 errors - Java Beginners
Getting 404 errors  Dear experts, I have embedded a login page inside my landing page - home.jsp. So, at the right-hand column of my page, I... I received a 404 errors and I identified that the servlet doesn't appear
Advertisements
i am Getting Some errors in Struts - Struts
i am Getting Some errors in Struts   I am Learning Struts Basics,I am Trying examples do in this Site Examples.i am getting lot of errors.Please Help me
errors
errors  i am getting an error saying cannot find symbol class string.how do i rectify
errors
that what the errors in above code
check for errors
check for errors  How can I check for errors
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
jsp errors - JSP-Servlet
. Now i am getting less errors compared to previous. But I am getting 2 errors...jsp errors  Hi I got errors when running a jsp file I am giving the file. this is from rose india. I set the class path for 3 jar files i.e
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
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
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
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
The errors tag
In this section, you will learn about the errors tag of the Spring form tag library
Correct errors - Java Beginners
Correct errors  Identify and correct the errors in the following program: public java Method { public static method1(int n, m) { n += m; xMethod(3. 4); } public static int xMethod(int n) { if (n > 0) return 1
WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?
WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?  WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP
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
date_get_last_errors
date_get_last_errors date_get_last_errors alias DateTime::getLastErrors function returns the warnings and errors while parsing a date/time string... about warnings and errors. Example: <?php $date = date_create('asdfasdf
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
Getting Exception
Getting Exception  How to get exception from commented code in java
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
getting variables
getting variables   how to get variables from servlet program to webservice program
Help please, some strange errors
this errors so i have posted the whole program here. Here i tried to make the monopoly... is causing that run-time errors? Any kind of help will be helpful to me. and let
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 NumberFormatException
Getting NumberFormatException  Thanks for the reply. Its works well, but whenever I'm using numeric value from 0010 to 0757 it is returning some garbage value. I dont have the idea what is going wrong. Please give me some idea
Getting NumberFormatException
Getting NumberFormatException  Hello Sir, I'm using Integer.parseInt(String str) function which returns a NumberFormatException(Unknown source). I also used Integer.parseInt(String str, int radix) but it also throws the exception
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
Display Errors using Message Resources - Struts
Display Errors using Message Resources  Hello.. I've a login page where i used applicationresources.properties to display errors for null values and i wrote the condition in formbean. Now i want to show the errors for invalid
How to show all errors in PHP?
How to show all errors in PHP? I this tutorial I will explain you how you can... all errors in PHP?" by the PHP developers. As it is necessary to see all the errors while developing PHP programs. What change I should make in the code
errors while run - Java Server Faces Questions
errors while run  I,ve download the SimpleHelloByEnteringName jsf intoduntion sample project and tried to run this application following the steps narrated in roseindia jsf tutorial. But i found the fillowing error:(My
Im not getting validations - Struts
Im not getting validations  I created one struts aplication im using...{ DynaActionForm studForm = (DynaActionForm)form; ActionMessages errors = new...")); } saveMessages(request,errors); if(errors.isEmpty()){ return
Calling hibernate query list() method generates errors
grpId){ Query q = getCurrentSession().createQuery("from JobEntity je where... of the job id from REFRESH to PERSIST, but still the same errors occur. Does cache
Coding errors for printing function, please help
Coding errors for printing function, please help  Hello, We, my classmates and I, wrote this software but I ran into problems with printing button. Can someone please take a look and help me to fix this. Although
Getting around in Agra
Getting around in Agra  Hi, I am looking for complete information on getting around in Agra? Thanks
verify the code and give me the code with out errors
clear the errors and give me correct tutorial for my knowledge improving.pls anyone
How to validate a form in action class and forward errors to the jsp in struts?
How to validate a form in action class and forward errors to the jsp in struts?  How to validate a form in action class and forward errors to the jsp in struts
Getting mysql table in textbox
Getting mysql table in textbox  how to get mysql table values into textbox in java using ajax and servlets
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
getting html list in a array
getting html list in a array  hi i want to get html unordered list in a array using jsp
GETTING ALERT MESSAGE
GETTING ALERT MESSAGE  how to get an alert message when radio button is selected instead of checkbox
getting files from VSS
getting files from VSS  I am not able to get the files from VSS.I am using following code. and just let me know is localpath attribute is for our local project path? I am getting the problem in this line failed
Getting an exception - JSP-Servlet
Getting an exception  Dear Sir , While sending a mail am getting an following exception javax.mail.MessagingException: 554 mail server permanently rejected message (#5. 3.0)so how to over come from this please help
Advertisements
 

 

 

DMCA.com