Please help me friends
I have a doubt in using array in JAVA

if my input is AB1CD
They are stored in array as
a[0]=A
a[1]=B
a[2]=1
a[3]=C
a[4]=D

I developed a coding to insert the number that appearing after a alphabet in the same array element like

a[0]=A
a[1]=B1
a[2]=C
a[3]=C
a[4]=D

The program is given below

import java.io.*;
class suba
{

public static void main(String args[]) throws IOException
{
String[] st= new String[100];
System.out.println("Enter the text :");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str=br.readLine();
st=str.split("");
for(int k=0;k<(st.length-1);k++)
{
st[k]=st[k+1];
}
//char ch[]=str.toCharArray();

for(int i=0;i<st.length-1;i++)
{

if((st[i].equals("0"))||(st[i].equals("1"))||(st[i].equals("2"))||(st[i].equals("3"))||(st[i].equals("4"))||(st[i].equals("5"))||(st[i].equals("6"))||(st[i].equals("7"))||(st[i].equals("8") )||(st[i].equals("9") ) )
{
st[i-1]=(st[i-1]+st[i]);
st[i]=st[i+1];
}
}

for(int j=0;j<st.length-1;j++)
{
System.out.println("A["+j+"]"+st[j]);
}
}
}

My problem is that i want to move the next consecutive element appearing after the number to array element of the number position. fr ex like

a[0]=A
a[1]=B1
a[2]=C
a[3]=D

I getting repeated alpabet and not able to delete the last position tat was unoccupied. Someone please help with it. Thanks fr ur help...... :) :)

Can you explain your logic in pseudo code that solves the problem? If you have a bad design then you should fix that.
If you have good logic, is your code following your logic?
Add some println statements to the code to show what it is doing. If you understand the what the logic should be, the printed output will help you see what the code is doing so you can fix it.

Please edit your code and give it proper indentation to show logic nesting levels. The statements should NOT all start in the first column.

Edited 4 Years Ago by NormR1

once a number is found you need to continue to move the next contents of the array until the last element so that there won't be a repeated value

The trick to moving contents up an array is that you have to start at the end of the array and loop downwards back to the starting point. If you start at the insertiuon point and loop upwards you just keep duplicaing the value that was at the starting point. Just try doing it on a sheet f papaer.

This article has been dead for over six months. Start a new discussion instead.