Help with simple program

Hello, all.

I have to make a simple program , here is what i need to do:

Input : ABC

Output : BCD

Input : EFG

Ouput : FGH

Input : zzz

Output : aaa

Input : ZaB

Output : AbC

(i.e i have to print the alphabet after the one entered, and if it is Z, print an A)

The program is simple enough, but i just cant seem to figure out how to fix a bug:

Basically , my problem is that it prints the ASCII values of the next characters, but not the characters themselves, for example on entering "ABC" the output will be 666768 (66- B 67-C 68-D)

Heres the code:

publicclass ABCtoBCD

{

publicvoid convert(String str)

{

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

{

if (str.charAt(i)==90)

{

System.out.print("A");

}

elseif (str.charAt(i)==122)

{

System.out.print("a");

}

else

{

System.out.print(str.charAt(i)+1);

}

}

}

}

[1705 byte] By [Overkilla] at [2007-11-27 9:38:16]
# 1
Currently, you're adding an integer to the character, which causes the result to convert to an integer. Cast the result to char, that is, substitute the last actual line of code with System.out.print((char) (str.charAt(i)+1));
georgemca at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...
# 2
Oh thanks... but we havent learnt casting - the only way we have learnt on how to convert datatypes is using Wrapper Class (like Integer.parseInt or Integer.toString)There is no wrapper class for char(i tried Character.parseChar), so is there some way using wrapper classes to do
Overkilla at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...
# 3

There's nothing to parse

I'm in a helpful mood. Have some code

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

{

if (str.charAt(i)==90)

{

System.out.print("A");

}

else if (str.charAt(i)==122)

{

System.out.print("a");

}

else

{

char c = str.charAt(i);

c++;

System.out.print(c);

}

}

Although I would say that just because you haven't been taught about casting yet, doesn't mean you shouldn't use it. When taking a course, it's expected that you will do some learning on your own - and you've learnt a bit about casting. You could use it, might even earn you credits, or brownie points. It's up to you, though, you know the course and what might or might not be appropriate better than I do

Anyways, you've got a couple of ways to do this. Go with whicheve r you think is best

georgemca at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...
# 4
Actually its not a course , im in school ^^ (10th std)Ill ask my teacher if its alright otherwise ill use the way you just posted, shouldve thought of that :(
Overkilla at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...
# 5

> Actually its not a course , im in school ^^ (10th

> std)

> Ill ask my teacher if its alright otherwise ill use

> the way you just posted, shouldve thought of that :(

For extra marks, submit both. It's worth bearing in mind that you might never be taught about casting. We weren't taught it on my University course, bizarrely

georgemca at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...
# 6
can you give me some 10 simple examples in javA programming?this is my email add lla_albeza@yahoo.comMessage was edited by: HeLp_The_PooR
HeLp_The_PooRa at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...
# 7
ihave an problem about the run of the java programe. here when i execute the programe it successfuly compile butwhen i run it there is an message that EXCEPTION IN THREAD" MAIN" JAVA.LANG.NO CLASSDEF FOUND ERROR:CLASS NAME
sushant.winnera at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...
# 8
@ HeLp_The_PooR and sushant.winnerYou would do better to create your own thread for your own question.
pbrockway2a at 2007-7-12 23:11:20 > top of Java-index,Java Essentials,Java Programming...