
how to print and total my id number ..for example if my id is 0123456789 the output will look like this :
0123456789
0+1+2+3+4+5+6+7+8+9=45
help me plz

Hi Friend,
Try the following code:
import java.util.*;
public class IDNumber{
public static String removeCharAt(String s, int pos) {
StringBuffer buf = new StringBuffer( s.length() - 1 );
buf.append( s.substring(0,pos) ).append( s.substring(pos+1) );
return buf.toString();
}
public static void main(String[] args){
Scanner input = new Scanner(System.in);
StringBuffer buffer=new StringBuffer();
System.out.print("Enter Number:");
String st = input.nextLine();
String [] arr = new String[st.length()];
int sum = 0;
for (int i = 0; i < st.length(); i++){
arr[i] = st.substring(i,i+1);
buffer.append(arr[i]);
buffer.append("+");
sum = sum + Integer.parseInt(arr[i]);
}
int len=buffer.length();
System.out.println(len);
String result=removeCharAt(buffer.toString(),19);
System.out.print(result+"="+sum);
}
}
Thanks

Hi, can you recommend a simple one using int array ? Because i cant understand the previous 1.Sorry and thanks a lot.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.