Results 1 to 8 of 8
Thread: need help with the program
- 01-08-2011, 01:20 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
- 01-08-2011, 01:24 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,385
- Blog Entries
- 7
- Rep Power
- 17
- 01-08-2011, 01:41 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
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
- 01-08-2011, 01:45 PM #4
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
to do a reverse for loop
to check if its a character or digit, you can use Character class method isLetterJava Code:for(int i = myString.length()-1 ;i>=0; i--){ System.out.println( myString.charAt(i) ); }
Java 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) }Last edited by JavaHater; 01-08-2011 at 01:50 PM.
- 01-08-2011, 01:51 PM #5
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
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
- 01-08-2011, 01:56 PM #6
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
the code which u sent me prints the string backwards
but the code which i want.
- 01-08-2011, 02:17 PM #7
Member
- Join Date
- Jan 2011
- Location
- Bangladesh
- Posts
- 1
- Rep Power
- 0
check this
////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);
}
}
- 01-08-2011, 03:08 PM #8
Member
- Join Date
- Jan 2011
- Posts
- 30
- Rep Power
- 0
Similar Threads
-
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 06:53 PM -
Execute A program from a Program!
By Moncleared in forum Advanced JavaReplies: 2Last Post: 02-22-2009, 04:17 PM -
Executing a program within a program
By gibsonrocker800 in forum New To JavaReplies: 5Last Post: 05-12-2008, 08:24 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks