Core Java
Hi,
I want to insert an elements inside an array. I have one array1 of size 5(where all teh indexs are full).I have created one more array2 of size 6 and inserted all the elemnts of array1 inside array2. Now I want to insert an element in 3rd postion of array2 such that elements present in 3rd position will move to 4th, 4th will move to 5th and 5th will move to 6.
I have developed a program below. But getting string index out of bound exception. Please help me to fix this issue.
package com.lara;
public class Array1
{
public static void main(String[] args)
{
int a[]= {1,2,3,4,5};
System.out.println("Normal Array:");
for(int k:a)
{
System.out.println(a[k-1]);
}
System.out.println("-------------");
int b[]=new int[6];
System.out.println("Length of B is:"+b.length);
System.out.println("---------------");
b=a;
for(int k:b)
{
System.out.println(b[k-1]);
}
System.out.println("-------xys----");
for(int i=5;i>=0;i--)
{
if(i>2 && i<5)
{
b[i+1]=b[i];
}
b[2]=30;
}
for(int j:a)
{
System.out.println(a[j-1]);
}
}
}
Regards:
Akash
View Answers
Related Tutorials/Questions & Answers:
core javacore java how to display characters stored in array in
core java core javacore java basic
java interview question
Advertisements
CORE JAVACORE JAVA
CORE JAVA PPT NEED WITH SOURCE CODE EXPLANATION CAN U ??
Core Java Tutorials
core javacore java Hi,
can any one expain me serialization,Deseralization and exterenalization in
core java core javacore java Hi,
can any one exain me the concept of static and dynamic loading in
core java core javacore java i need
core java material
Hello Friend,
Please visit the following link:ADS_TO_REPLACE_1
Core Java
Thanks
core javacore java how can we justify
java technology is robust
Core JAvaCore JAva how to swap 2 variables without temp in
java core javacore java write a
java program to view product details from product table
Core JavaCore Java How to execute cmd command through
java??
Give Code of them
core javacore java its compulsory to save file name and class name is same in
java CORE JAVACORE JAVA What is Garbage collection in
java? What is the role of a developer for garbage collection
core javacore java In
java primitive variables will get its default value automatically after declaration. Then why it is mandatory to initialize a variable before using
Core JavaCore Java Please write a
Java Program to design login form and store the values in file & validate and display the MainForm
Core JavaCore Java Hi,
Can any one please share the code for Binary search in
java without using builtin function
core javacore java Hello sir,What is logic behinde the
core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
core javacore java Hello sir,What is logic behinde the
core java programms,How may programmas are there,for example,sorting of two numbers,grade of the student details,fibonice serice,paldroma,incremting of the program,asscedding
Core JavaCore Java How to load class dynamically in
java ?
To load class dynamically you can use Class class method
Class.forName("abc.xyz.MyClass");
This method load the given class at run time
Core JavaCore Java Hi,
can any one please tell me the uses of return type,"Super" and "this" calling statement in
Java??
why do we required this,super calling statement??
why return type is required
Core JavaCore Java Hi,
Can any one please expain me why derived data types are required in
java as we have primitive data types with us
Core JavaCore Java Hi,
Can any one please expain me why derived data types are required in
java as we have primitive data types with us
Core Java Core Java How can i write own compile time and runtime exceptions in
java
Hello Friend,
Please visit the following links:
http://www.roseindia.net/
java/exceptions/how-to-throw-exceptions.shtml
http
Core javaCore java How to use hyperlink that is href tag in
core java without swing, frames etc.
My code is
StringBuffer oBodyStringBuffer = new StringBuffer("Message Classification: Restricted.\n\n
core javacore java surch the word in the given file
CORE JAVACORE JAVA What is called Aggregation and Composition
Core JavaCore Java Is
Java supports Multiple Inheritance? Then How ?
Hi Friend,
Java does not support multiple inheritance but it can be achieved by using the interface.ADS_TO_REPLACE_1
In
Java, Multiple Inheritance can
core javacore java I am having 10 countries in the data base as back end.in front end i am having a button in web page like SHOWCOUNTRIESLIST so i need
java code how to retrive that 10 countries from back end to my page,,pls help me
Core Java Core Java Hi,
Can any one please tell me the program to print the below matrix in a spiral order.
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Thanks a lat in advance
core javacore java what is the use of iterator(hase next
core javacore java please give me following output
Core javaCore java difference between the string buffer and string builder
core javacore java how to write or update into excel file using...; Please visit the following links:
http://www.roseindia.net/tutorial/
java/poi/insertIntoExcelFileData.html
http://www.roseindia.net/answers/viewqa/
Java Core JavaCore Java can any one please tell me the difference between Static and dynamic loading in
java???
The static class loading is done through the new operator while dynamic class loading is achieved through Run time
Core JavaCore Java What is the significance of static synchronized method?
Why do we have the method declared as static synchronized
core javacore java how to compare every character in one string with every character in other string
core javacore java what is the max size of array?
You can declare up to maximum of 2147483647
Core JavaCore Java Write a Program to add given number of days to the current system date and display the same
Core JavaCore Java have to find the prime numbers which is less than the current prime numbers using loops
core javacore java can i use native keyword with abstract method ? if yes explain and if no please explain
core javacore java Hi,
Can any one please share a code to print the below:
1
121
12321
1234321
CORE JAVACORE JAVA Tell me some Scenarios why you go for Abstract Class and Interface
Core javaCore java how to convert reverse of String without using String function
core javacore java Is it possible to create a shallow copy of an arraylist instance? if yes then please post the code
Core JavaCore Java Is
Java supports Multiple Inheritance? Then How ?
There is typo the question is ,
What is Marker Interface and where it can be used?
Hi Friend,ADS_TO_REPLACE_1
An interface with no method
core javacore java what does the term web container means exactly?please also give some examples
Hi,
In
Java Platform, Enterprise Edition specification, servlet container comes into picture. It is also know as web container
core javacore java
java program using transient variable
Hi Friend,
A transient variable is a variable that may not be serialized.The transient..., visit the following link:
http://www.roseindia.net/help/
java/t/transient-
java core java - Java BeginnersCore Java interview Help
Core Java interview questions with answers Hi friend,Read for more information.http://roseindia.net/interviewquestions
JAVA(core) - Java BeginnersJAVA(
core)
Core Java In
java 'null' is keyword which means object have nothing to store. even not allocated memory