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




Have Programming Question? Ask it here!
 
 
 


UvarajS
Zoho interview Quest
5 Answer(s)      10 months ago
Posted in : Java Interview Questions


Input array 1,2,3,4,5,6 Output 1,3,5,0,0,0 Remove even nos and fill it with zeros U can use only one loop for ur logic Two variables apart from the array.


Advertisement
View Answers

June 2, 2013 at 7:04 PM


Try the following code friend may, this will be helpful for you.

class RemoveEvenNumber
{
   int a[] = new int[]{1,2,3,4,5,6};
   int b [] = new int[a.length];  

   public void removeEvenNumber()
     {
          int i = 0;
          while(i< a.length)
             {                  
                 if(a[i] % 2 == 0)
                  {
                     a[i]=0;                     
                  }
                 else if(a[i] % 2== 1)
                  {                       
              b[i]=a[i];                       
                  }
                System.out.print(b[i]+",");                
               i++;
             }                      
      }

   public static void main(String args[])
      {
          RemoveEvenNumber remove = new RemoveEvenNumber();
          remove.removeEvenNumber();         
      }
}


June 3, 2013 at 11:40 AM


Here is the program :

import java.util.Scanner;

/**
 * @author JavaWithUs 
 * www.javawithus.com
 */
public class RemoveEvenNumbers {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("Enter length of array: ");
        int[] arr = new int[s.nextInt()];
        System.out.println("Enter elements:");
        for (int i = 0; i < arr.length; i++) {
            arr[i] = s.nextInt();
        }
        int numberOfZeroes = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 0) {
                arr[i] = 0;
                numberOfZeroes++;
            }
        }
        System.out.println("Modified array:");

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != 0) {
                System.out.print(arr[i] + " ");
            }
        }
        for (int i = 0; i < numberOfZeroes; i++) {
            System.out.print("0 ");
        }
    }
}

Here is the output :

Enter length of array: 
6
Enter elements:
1 2 3 4 5 6
Modified array:
1 3 5 0 0 0

To learn about arrays, see these pages :



August 11, 2013 at 7:43 AM


public class Evenodd {

public static void main(String[] args) {

int g=0,i; int a[ ]={1,2,3,4,5,6}; int n=a.length; for(i=0;i



August 25, 2013 at 1:48 AM


/*

One Loop and two variables are used. Runtime o(n*n)

*/

public class OneLoopTwoVariables {

public static void main(String x[])
{

    int xArray[]={1,2,3,4,5,6,7};
    int xCnt=0,xTmp=0;

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

            if(xCnt==0 )
            {

                if(xArray[i]%2 == 0)
                    {
                        xArray[i]=0;
                    }

            }

            else if(xCnt == (xArray.length * xArray.length))
            {
                System.out.print(xArray[i]);
            }

            else

            {
                if(xArray[i] == 0)
                {
                    if(i+1 != xArray.length)
                    {
                        xTmp = xArray[i+1];
                        xArray[i+1] = 0;
                        xArray[i] = xTmp;
                    }
                }
            }


        if(i == xArray.length-1) { 

            i=-1; 
            xCnt+=1;

            if(xCnt == (xArray.length * xArray.length)+1){ break; }

        } 

    }

}

}



October 29, 2013 at 3:43 PM


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

private void removeEven()
{
for (int i = 0; i < a.length; i++)
{
    if (a[i] == 0 || a[i] % 2 == 0)
    {
    traverseArray(i);
    }
    System.out.print(a[i]);

    if (i != a.length - 1)
    System.out.print(", ");
}
}

private void traverseArray(int i)
{
if (i != a.length - 1)
{
    a[i] = a[i + 1];
    a[i + 1] = 0;

    traverseArray(i + 1);
}
}


Related Tutorials/Questions & Answers:
Zoho interview Quest
Zoho interview Quest  Given a string , you have to predict whether it can be changed into a palindrome or not by changing the positions of the characters Eg. Tests Yes Explanation:tests can be changed to tsest or stets
Zoho interview Quest
Zoho interview Quest  Print the pattern N=4 4444444 4333334 4322234 4321234 4322234 4333334 4444444 N=3 33333 32223 32123 32223 33333
Advertisements
Zoho interview Quest
Zoho interview Quest  Input array 1,2,3,4,5,6 Output 1,3,5,0,0,0 Remove even nos and fill it with zeros U can use only one loop for ur logic Two variables apart from the array.   Try the following code friend may
Zoho Writer
Zoho Writer       Zoho Writer is a web-based word processor currently in beta. It is much like Writely. Zoho Writer Zoho Writer is the component of Zoho's Online Office
interview - Java Interview Questions
interview  kindly guide me some interview questions of Java
Interview Que
Interview Que  I want to Java Interview Questions   Please visit the following link: Java Interview Questions
Interview Question - Java Interview Questions
Interview Question  I need Interview Questions on Java,J2EE Pls help me
interview questions - Java Interview Questions
interview questions for Java  Hi Any one can u please post the interview point of questions.Warm Regards, Satish
Interview question
Interview question  what is mean by Dynamic class loading
Interview question - Java Interview Questions
Interview question   Hi Friends, Give me details abt synchronization in interview point of view. I mean ow to explain short and neat. Thanks
Interview Tips - Java Interview Questions
Interview Tips  Hi, I am looking for a job in java/j2ee.plz give me interview tips. i mean topics which i should be strong and how to prepare. Looking for a job 3.5yrs experience
tech. interview
tech. interview   java support round robin algo. if yes why? and if no why
Interview question - JSP-Interview Questions
Interview question   Hi Friend, Can we inherit interface in JSP. Thank u in advance
java interview question and answer - Java Interview Questions
java interview question and answer   sir, i want one mark java interview question and answers
interview question - Java Interview Questions
interview question  hello i want technical interview question in current year   Hi Friend, Please visit the following links: http://www.roseindia.net/interviewquestions/ http://www.roseindia.net
interview question - Servlet Interview Questions
interview question  What is Servlet? Need interview questions on Java... and HTTP Servlet.While going through an interview you could be asked for number... according to your experience.And for collection of Java Servlet Interview Question you
Client Interview
Client Interview  Hi, I am kumar i am having client round in polaries client is a BANK. how to face client interview. what are the expected questions from CITI
java interview - JSP-Interview Questions
java interview  what type of questions would be asked to a 3 years experience person in java? can anyone please provide list of topics or interview questions for 3 years experience in java
java - Java Interview Questions
Helpful Java Interview questions   Need Helpful Java Interview questions
Struts - Java Interview Questions
Struts Interview Questions  I need Java Struts Interview Questions and examples
Jsp - Java Interview Questions
Need JSP Interview Questions  Hi, I need JSP interview questions.Thanks
struts interview Question - Struts
struts interview question and answer java  struts interview question and answer java
Java Interview Questions
Java Interview Questions  Hi, Can anyone tell the urls of Java Interview Questions on roseindia.net? Thanks
About interview questions
About interview questions   I want interview questions on IDE's Please send links
Interview question - Java Interview Questions
Interview question   Hi Friends, I am new to java, can u tell me what is class ,object and instance with example. For example : class raja , raja r = new raja(); ,here raja is class and r is instance
java - Java Interview Questions
java  MNC now which modal question are asked in interview
Hi - Hibernate Interview Questions
Hi   please send me hibernate interview questions
java interview question
java interview question  when will we use abstraction or interface
JAVA INTERVIEW QUES
JAVA INTERVIEW QUES  what is meant by CTS in JAVA
struts interview question in ibm
struts interview question in ibm  what is the use of "format" attribute
interview path pdf
interview path pdf  Plz send me the paths of java core questions and answers pdfs or interview questions pdfs... the interview for any company... the following link: Interview Questions and their Answers
java interview question
java interview question  what is the usage of abstract class
Hibernate interview Questions
Hibernate interview Questions  Pl share hibernate interview..., but in that they have currently not updated interview questions. They have explain so many new technology with pictorial example and sample programs but interview question
Hibernate - Hibernate Interview Questions
hibernate interview questions and answers  Hi, Can anyone give me the best reference of hibernate interview questions and answers?Thanks in advance
java - Servlet Interview Questions
java  servlet interview questions  Hi friend, For Servlet interview Questions visit to : http://www.roseindia.net/interviewquestions/servlet/ Thanks
interview question
interview question  write a method that takes and return an object of your own type?   Hi Friend, Try the following code: class TakeAndReturnObject{ public static String getLargestWord(String st){ String[] str
interview questions - EJB
interview questions in Java  Need interview questions in Java ...://www.roseindia.net/ejb/Interview Questions: http://www.roseindia.net.... If you really want to win the interview then follow the steps.Learn core java http
a interview questioon
a interview questioon  write a programme so the it can print each substring of a string like "saswat" is the string then it will print s,a,w,t,sa,swa,sta,as,aws,ats,sasw all posible sub string with out repeating   Hi
interview questin of java - Java Interview Questions
interview questin of java  what r the common question of core & addvance java in interview?  Hi Garima, I am sending you a link. This link will help you. please visit for more information. http
one interview question - Java Interview Questions
one interview question   Hello, In one of my interview the interviewer ask one question "what are the problems you faced during project implementation", can any body tell me what should be the appropriate answer
Hibernate Interview question - Hibernate Interview Questions
Hibernate Interview question  Hi, My interviewer asked, in hibernate how u know whether data is updated or saved or deleted. Thanks in advance
interview questions
interview questions   Tell us about a situation where you had to solve a difficult problem. What did you do? What is your typical way of dealing with conflict? Give us an example. Tell us about a problem that youââ?¬â?˘ve solved
interview questions
interview questions   Tell us about a situation where you had to solve a difficult problem. What did you do? What is your typical way of dealing with conflict? Give us an example. Tell us about a problem that youâ??ve solved
interview questions
interview questions   Tell us about a situation where you had to solve a difficult problem. What did you do? What is your typical way of dealing with conflict? Give us an example. Tell us about a problem that youâ??ve solved
interview questions
interview questions   Tell us about a situation where you had to solve a difficult problem. What did you do? What is your typical way of dealing with conflict? Give us an example. Tell us about a problem that youâ??ve solved
Interview question link - Java Beginners
Interview question link  Hi, I want JAVA+J2EE interview question and answer please suggesion me link
help me - Java Interview Questions
interview questions java pdf   Do you have any PDF for Java Interview questions
pls send maven interview questions
pls send maven interview questions  pls send maven interview questions to anvesh2406@gmail.com
HR Interview,Interview the Interviewer
HR Interview Advice - Interview the Interviewer... are now at the end of your interview session. What next? The answer... to ask the HR a volley of questions and turn it into a counter interview. Consider
Advertisements
 

 

 

DMCA.com