Results 1 to 3 of 3
- 07-05-2012, 07:36 AM #1
string printing converted to numbers while using ".charAt(1)+.chatAt(2)"
Hi,
I'm back I was to exams, My project is over.. thanks to the moderators..
My coding is
output:Java Code:public class stringing { public static void main(String[] args) { String a=new String("bcaefdhigklj"); for(int i=0;i<a.length();i=i+3) { //System.out.println(a.charAt(i+1)+"\n");//here it works fine System.out.println(a.charAt(i+1)+a.charAt(i+2)+a.charAt(i)+"\n"); //but here it prints numbers } } }
regardsJava Code:294 303 312 321
dhilip
- 07-05-2012, 08:03 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: string printing converted to numbers while using ".charAt(1)+.chatAt(2)"
When you concatenate chars using the (+) operator the value will be converted into the ASCII code that represent the char. For instance a = 97; b = 98; c = 99, etc. To make it concatenate as a string you need to convert the chars into string. The simplest way is to concatenate a string with it, you can write it like:
Java Code:System.out.println("" + a.charAt(i + 1) + a.charAt( i + 2) + a.charAt(i));Website: Learn Java by Examples
- 07-05-2012, 08:10 AM #3
Re: string printing converted to numbers while using ".charAt(1)+.chatAt(2)"
thx(:
dhilip
Similar Threads
-
Difference between String str1 = "hi"; and String str2 = new String("hi");
By saiganesh44 in forum New To JavaReplies: 1Last Post: 05-07-2012, 05:35 PM -
Exception in thread "main" java.lang.NumberFormatException:input string: "060320
By renu in forum New To JavaReplies: 14Last Post: 04-08-2011, 06:01 PM -
string comparison with "=" and ".equal"
By guavajuice in forum New To JavaReplies: 9Last Post: 04-22-2010, 09:01 PM -
final String currentWorld = "Java Forums"; String.format("Hello %s", currentWorld);
By mcfrog in forum IntroductionsReplies: 0Last Post: 04-02-2009, 07:02 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks