{
...
String b;
char a,y;
int k = 1;
...
b = readWord(); // input is the letter 'A'
a = b.charAt(0);
y = a + k;
print(y);
...
}
output: 66 ('B' in ASCII) but i want the letter 'B' to be put out. how can i convert the "int" into a "char" again?
later i want to 'crypt' a whole string.
thx and nice greez
ps.: sorry for the sloppy english! :rolleyes:
03-30-2003, 11:17 AM
ArchAngel
It's quite simple, you just do a cast to a char:
int numericValue = 66;
char c = (char)numericValue;
This 'forces' the value into a character variable.
03-30-2003, 02:03 PM
chrispi
already tried it like this:
String b;
char a,z;
int x;
print("String: ");
b = readWord();
a = wort.charAt(0);
x = a;
z = (char)x;
println(z);
doesn't work :(
whats wrong? :confused:
thx for helping, greez
chris
03-30-2003, 04:49 PM
ArchAngel
I adjusted your code to get it to compile and it behaved as expected, in this case, printing out 'B'.
Code:
public class Test {
public static void main(String[] args) {
String b;
char a,z;
int x;
System.out.println("String: ");
b = "Beautiful!";
a = b.charAt(0);
x = a;
z = (char)x;
System.out.println(z);
}
}
Run this code. Tell me if this is what you want.
ArchAngel.
04-11-2003, 12:45 PM
vercingetorix
Hi, out of curiosity I tried to run your code.. with
import java.swing.*; above the code. And then: 'java Test' at the prompt to create java application.
The error encountered it says:
$ /usr/j2se/bin/java test
Exception in thread "main" java.lang.NoClassDefFoundError: Test
Wonder what exactly is the problem?
Is System.exit( 0 ); needed b4 the end of the main to terminate application?
04-11-2003, 03:02 PM
vercingetorix
I got it! I should have compiled it with javac then run with java Test.