Share on Google+Share on Google+

1 Answer(s)      4 years and 3 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
called; 2.Create two arrays. One of them must store integer numbers... the numbers in the second array by 3; 7.Print out the contents of both arrays. 8.Swap
Arrays in java
Arrays in java  what is param array in java
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 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 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
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
How to create arrays in JavaScript?
How to create arrays in JavaScript?  How to create arrays in JavaScript
create arrays in JavaScript
create arrays in JavaScript  How to create arrays in JavaScript
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
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
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
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>
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? file location SASLError using PLAIN: not-authorized


Advertisement null