现在,这个代码在一台机器上工作绝对正常,但在另一台机器中只是简单地拒绝输出正确的结果。charAt产生不同的输出
这是一个简单的Initials输出请求。我对代码没有任何疑问,但我的问题是为什么它会输出数字而不是字母?
当使用Eclipse(开普勒)从我的笔记本电脑运行代码没有问题,我收到了信件。如果我使用其中一个可用的桌面和相同版本的Eclipse,则会得到一个整数。这可能是设置,但我不知道为什么。而重写的代码对输出
import java.util.Scanner;
public class InitialHere {
public static void main(String[] args)
{
// TODO Auto-generated method stub
//Using input keyboard
Scanner kb = new Scanner(System.in);
String firstname,lastname;
//Requesting names
System.out.print("What is your first name?");
firstname = kb.nextLine();
System.out.print("What is your last name?");
lastname = kb.nextLine();
//Calculating the initials
char achar = firstname.charAt(0);
char bchar = lastname.charAt(0);
//Output
System.out.println("Your initials are " + achar + bchar);
准确的输入和输出是什么? – Keerthivasan
想象一下,输入是汤姆沃尔顿,结果应该是TW。但它最终是171. – Snorrarcisco
哦,真的,你有没有sysout出'firstname'和'lastname'之前呢? – Keerthivasan