program for u will be given a string which will have characters and numbers,u have to parse from behind untill u find a character and print rest of the string
for example hello123world12 = hello123world 12
Printable View
program for u will be given a string which will have characters and numbers,u have to parse from behind untill u find a character and print rest of the string
for example hello123world12 = hello123world 12
i need a java program for a string which has characters and numbers
for example
String s = "hello123world12";
and i have to use for loop
and print the string as
hello123world 12
i have to read the string from back and stop reading when i find a chracter so in my example when i read d i have to stop reading the string and print hello123world 12.
i hope i am clear now
to do a reverse for loop
to check if its a character or digit, you can use Character class method isLetterCode:for(int i = myString.length()-1 ;i>=0; i--){
System.out.println( myString.charAt(i) );
}
Code:if ( Character.isLetter ( .... ) ){
// record the value of i. this value can be used to do a substring later if you want (using String.substring() method)
}
thank you .if possible can u tell me the full code.it is the assignment given to me.i tried to do it.and 2day by 9:30 i have to submit the code.
thank you very much
the code which u sent me prints the string backwards
but the code which i want.
////may be this can do
public static void main(String[] args) {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while(true)
try{
String s = in.readLine().toString();
String s1="",s2="";
////parsing string
int i=0;
for(i=s.length()-1;i>=0;i--)
if( s.charAt(i)>= '0' && s.charAt(i)<= '9')
continue;
else break;
s1 = s.substring(0, i+1);
s2 = s.substring(i+1);
System.out.println("Parsed String:::: "+s1+" "+s2);
}catch(Exception e)
{
System.err.println(e);
}
}
thank you very much