这个java程序有什么问题
publicclasshehe{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubchar...
public class hehe {
public static void main(String[] args) {
// TODO Auto-generated method stub
char ch1,ch2,ch3;
System.out.print("Enter first character:");
ch1=Keyboard.readChar(); //移去缓冲区的回车符
Keyboard.skipLine(); //这行有问题
System.out.println();
System.out.print("Enter second character:");
ch2=Keyboard.readChar(); //这行有问题
System.out.println();
System.out.print("Enter third charater:");
ch3=Keyboard.readChar(); //这行有问题
System.out.println();
if(ch1<=ch2)
{
char temp;
temp = ch1;
ch1 = ch2;
ch2 = temp;
}
if(ch1<=ch3)
{
char temp;
temp = ch1;
ch1 = ch2;
ch2 = temp;
}
if(ch2<=ch3)
{
char temp;
temp = ch2;
ch2 = ch1;
ch1 = temp;
}
System.out.print("Sorted:");
System.out.println(ch1);
System.out.println(ch2);
System.out.println(ch3);
}
} 展开
public static void main(String[] args) {
// TODO Auto-generated method stub
char ch1,ch2,ch3;
System.out.print("Enter first character:");
ch1=Keyboard.readChar(); //移去缓冲区的回车符
Keyboard.skipLine(); //这行有问题
System.out.println();
System.out.print("Enter second character:");
ch2=Keyboard.readChar(); //这行有问题
System.out.println();
System.out.print("Enter third charater:");
ch3=Keyboard.readChar(); //这行有问题
System.out.println();
if(ch1<=ch2)
{
char temp;
temp = ch1;
ch1 = ch2;
ch2 = temp;
}
if(ch1<=ch3)
{
char temp;
temp = ch1;
ch1 = ch2;
ch2 = temp;
}
if(ch2<=ch3)
{
char temp;
temp = ch2;
ch2 = ch1;
ch1 = temp;
}
System.out.print("Sorted:");
System.out.println(ch1);
System.out.println(ch2);
System.out.println(ch3);
}
} 展开
1个回答
展开全部
KeyBoard的作用是什么啊!
追问
从键盘输入啊
追答
应该是这样的吧!你就想从键盘输入三个字符吧!
public static void main(String[] args) {
// TODO Auto-generated method stub
char ch1,ch2,ch3;
Scanner Keyboard = new Scanner(System.in);
System.out.print("Enter first character:");
ch1=Keyboard.next().charAt(0); //移去缓冲区的回车符
// Keyboard.skipLine(); //这行有问题
System.out.println();
System.out.print("Enter second character:");
ch2=Keyboard.next().charAt(0); //这行有问题
System.out.println();
System.out.print("Enter third charater:");
ch3=Keyboard.next().charAt(0); //这行有问题
System.out.println();
if(ch1<=ch2)
{
char temp;
temp = ch1;
ch1 = ch2;
ch2 = temp;
}
if(ch1<=ch3)
{
char temp;
temp = ch1;
ch1 = ch2;
ch2 = temp;
}
if(ch2<=ch3)
{
char temp;
temp = ch2;
ch2 = ch1;
ch1 = temp;
}
System.out.print("Sorted:");
System.out.println(ch1);
System.out.println(ch2);
System.out.println(ch3);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询