prints characters in one case, but in another it returns integers. Why is that?
Hell again,
so here is the new one. The Java Tutorial that I am following says the following:
"Write a program that computes your initials from your full name and displays them."
so I wrote the following, making up a name for it and using examples previously encountered in the tutorial:
Code:
public class MyInitials {
public static void main(String[] args){
String myName = "Roger Justice";
int gap = myName.indexOf(' ');
System.out.println(gap);
System.out.println(myName.charAt(0));
System.out.print((myName.charAt(0) + (myName.charAt(myName.indexOf(' ')+1))));
}
}
When I use the following, I get this output. So I get a number of 156 instead of RJ:
(oh, feel free to ignore the first System.out.println. I was just tinkering with things.
Code:
----jGRASP exec: java MyInitials
5
R
156
----jGRASP: operation complete.
However if split the output over two lines, I get the desired outcome:
CODE:
Code:
public class MyInitials {
public static void main(String[] args){
String myName = "Roger Justice";
int gap = myName.indexOf(' ');
System.out.println(gap);
System.out.println(myName.charAt(0));
System.out.print((myName.charAt(0)));
System.out.println((myName.charAt(myName.indexOf(' ')+1)));
}
}
I get this output, the desired one:
Code:
----jGRASP exec: java MyInitials
5
R
RJ
----jGRASP: operation complete.
I don't understand why this happens.