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

Have Programming Question? Ask it here!

1 Answer(s)      a year and 8 months ago
Posted in : Java Beginners

can anyone help me out with this two programs plz?? in a main class ,create an array {4,34,5,3,6,8,1} remove 3 and 5th element and shift following left and adding zero at the end of array... another one is to search a numeric value nd search it plzz...

View Answers

January 2, 2013 at 3:58 PM

hi nick, I hope this example will helpful for you. The sample code given below is for removing the elements from the given list of array.

public class JavaRemoveArrayElementExample {    

    public static void main(String args[])
        int num[]= {4,34,5,3,6,8,1};
        int tempArray[]= new int[num.length];
        int tempArray1[]= new int[num.length-3];
        int tempArray2[]= new int[num.length-5];
        int tempArray1And2[] = new int[(tempArray1.length+
        int tempArray3[] = new int[tempArray1And2.length-3];
        int tempArray4[] = new int[tempArray1And2.length-4];
        int tempArray3And4[] = new int[tempArray3.length+

        System.arraycopy(num, 0, tempArray, 0, num.length);
        //Removing 3rd position element from original array
        System.arraycopy(num, 0, tempArray2, 0, num.length-5);
        System.arraycopy(tempArray, 3, tempArray1, 0, 

        System.out.println("Array list after removing 3rd " +
                "position \n element from the original array list");
        for(int i=0; i<tempArray2.length; i++)

        for(int i=0; i<tempArray1.length; i++)
        //Merging array list tempArray2 and tempArray1
        System.arraycopy(tempArray2, 0, tempArray1And2, 
                0, tempArray2.length);
        System.arraycopy(tempArray1, 0, tempArray1And2, 
                tempArray2.length, tempArray1.length);

        System.out.println("List after merge");
        for(int i =0; i<tempArray1And2.length; i++)
        //Removing 5th position element from original array
        System.arraycopy(tempArray1And2, 0, tempArray3, 0, 
        System.arraycopy(tempArray1And2, 4, tempArray4, 0, 

        System.out.println("Array list after removing " +
                "5th position \n element from the original list");
        for(int i=0; i<tempArray3.length; i++)

        for(int i=0; i<tempArray4.length; i++)
        //Merging array list tempArray3 and tempArray4
        System.arraycopy(tempArray3, 0, tempArray3And4, 0, 
        System.arraycopy(tempArray4, 0, tempArray3And4, 
                tempArray3.length, tempArray4.length);
        System.out.println("Final array list after removing 3rd " +
                "\n and 5th position elements from the original list");
        for(int i = 0; i <tempArray3And4.length; i++)

Related Tutorials/Questions & Answers:
arrays  using arrays in methods   Java use arrays in methods import java.util.*; class ArrayExample{ public static int getMaxValue(int[] arr){ int maxValue = arr[0]; for(int i=1;i < arr.length;i
Store a table with students and information (name, ID, password, crypted password, etc) in a multi-dimensional array "stud"  Arrays and Strings: Store a table with students and information (name, ID, password, crypted password
Arrays   Hi I need help with the following exercises. Exercise 1: Write a Java application in which the user is prompted for the total number of integer values to be stored in an array. Initialize the array with random values
Arrays in java
Arrays in java  what is param array in java
java arrays
java arrays  can i know how can we intilize the three dimentional arrays in java? and how can we assign thae values to that array
java arrays
java arrays  i need a java program to store student details like id,name,addr,marks,average,total..using arrays..input data using scanner class and by using class, object and constructor
Java with Arrays
Java with Arrays  I was given the assignment to create two parallel arrays; both of size 50 (declares 50 as a constant) One is an array of strings... and store it in the arrays. The input for the problem should be provided in a text
java arrays
java arrays  how do you write the code for multipliying 2 double arrays to be in a 3rd double array? here is my code: package employeepay; /** * * @author Owner */ public class Main { /** * @param args the command line
create arrays in JavaScript
create arrays in JavaScript  How to create arrays in JavaScript
How to create arrays in JavaScript?
How to create arrays in JavaScript?  How to create arrays in JavaScript
Compare two Byte Arrays?
Compare two Byte Arrays?  Compare two Byte Arrays
Comparing arrays not working correctly?
Comparing arrays not working correctly?  Comparing arrays not working correctly
arrays in java - Java Beginners
arrays in java  Hi All, I have two arrays. in this two array some name are same. I want to merge those arrays into single. But while merging I want to delete duplicate entries. How merge those arrays. Thanks, mln15584
java; arrays - Java Beginners
java arrays example  How can you create a program, by using arrays and the output would be X. by using char or string.Thank you
What is javascript Arrays?
What is javascript Arrays?   Hi, I am learner of JavaScript. My question is that What is JavaScript Arrays ? How to Define the JavaScript arrays in you program. Please give an example show that i will try my self. Thanks
Are arrays primitive data types?
Are arrays primitive data types?   Hi, Are arrays primitive data types? thanks   Hi, In Java, Arrays are objects. Identifier are some simple variable names which is defined as the value container. The type of value
combine two arrays in php
combine two arrays in php  combine two arrays in php   $newArray = array_combine($diff, $pages_name['data']); foreach ($newArray as $data) { var_dump($data); exit('zzzzz'); echo $data . '<br>
reverse arrays in java
reverse arrays in java  how do i make a code that can be used to reverse the elements of an array in two dimension such that the last element of an array becomes the first element of the array and the first element of an array
reverse arrays in java
reverse arrays in java  how do i write a program in array of size n*m where both n and m are greater than 20 such that the 1st element of an array becomes the last and vice verse
Arrays in java 7
This tutorial describes the concept of Arrays in java 7
intersection of two java arrays
intersection of two java arrays  I am trying to figure out how to compare two arrays and get the intersection and put this into a third array of the correct size. I know how to copy the two arrays into the third array but am
Arrays in java
Arrays in java Arrays are the data structure of java , we use array where we need contiguous memory allocation. Array stores same type of data structure. Array type is checked at compile time. An array has a fixed length. Declaration
How to concatenate two arrays in Java?
How to concatenate two arrays in Java?  How to concatenate two arrays in Java
Java Arrays Tutorials
The java.util.Arrays class helps the programmers to manipulating the arrays. It provides the methods to easily manipulate the arrays. Methods provided...(). Browse the following code to Learn Java Arrays in detail
Variable length arrays?
Variable length arrays?  Hi: I enjoy reading from your site especially the example seem to speak louder than the description. Thanks for your... of arrays or if there is a smart way to handle this. Thanks for your help. Varma
Introduction to java arrays
Introduction to java arrays   ... of Arrays in Java Programming language. You will learn how the Array class... arrays. To meet this feature java has provided an Array class which abstracts
Arrays - Java Interview Questions
a program that take arrays A & B as input and find missing element in B array
Printing 2 arrays
Printing 2 arrays  Hi, I have 2 arrays: String [] head = {"Name", "Date of birth", "PPS number"}; String [] personal= {value1, value2, value3}; I want this 2 arrays to be printed out in the following manner: head[0] tab
Comparing Arrays
Comparing Arrays : Java Util       This section show you how to determine the given arrays are same or not. The given program illustrates you how to compare arrays according
Associative Arrays
Associative Arrays In this section, you will learn about associative arrays and it 's implementation. In an associative array, a key is associated with a value. We can use values as key and assign value to them. Given below
arrays help - Java Beginners
arrays help  Write a program that sorts values. ? The program includes readIntegers() that o reads the user inputs o stores them in an array, and o returns the array   ? The program includes easySort() that o sorts
java 2d arrays
. and if i do it manualy it is wrong. public class Arrays { public static void main
Merging Two Arrays Of Different Lengths
Merging Two Arrays Of Different Lengths  I have two arrays of different lengths and wants to have merged values into third. The only condition is, I want unique values in it(third array). Thanks In Advance
arrays - Java Interview Questions
a program that take arrays A & B as input and find missing element in B array
Arrays, loops and string handling
Arrays, loops and string handling  How would i go about in creating a program to mark and grade a set of multiple choice test results. this is a console program that uses JOptionPane dialog boxes as well. Read a set of 10
reverse two dimensional arrays in java
reverse two dimensional arrays in java  reverse array elements in two dimensional array such that the last element becomes the first
Iterating java arrays
Iterating java Arrays arrays can be iterated by the for, for each loop. array elements can be added to the list and then it can be iterated by the iterator() method. Example 1 public class