当前位置: 代码迷 >> Java相关 >> 新手 字符输出 编译不过
  详细解决方案

新手 字符输出 编译不过

热度:274   发布时间:2013-07-06 20:27:41.0
新手 字符输出 编译不过
错在哪?那些地方可以简化   自学  谢谢
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;

/**
*
* @author Administrator
*/import java.io.*;
public class JavaApplication3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      
         char ch;
        System.out.print("请输入一个字符");
        try
        {   ch=(char)System.in.read();}
        catch(IOException e){ }
        System.out.println("字符"+ ch +"的ASCII码值是"+(int)ch);// TODO code application logic here
    }
}
搜索更多相关的解决方案: command  package  public  change  import  

----------------解决方案--------------------------------------------------------
这样就可以了:
public class JavaApplication3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      
         char ch = 0;
        System.out.print("请输入一个字符");
        try
        {   
            ch=(char)System.in.read();
            }catch(IOException e){
               
            }
        System.out.println("字符"+ ch +"的ASCII码值是"+(int)ch);// TODO code application logic here
    }
}

----------------解决方案--------------------------------------------------------
怎么不结贴啊。楼上正解
----------------解决方案--------------------------------------------------------
异常的话你得引入一个包,其实说不上简化什么的,就是得看你自己的习惯,要想很规范的写的话,可以去网上看看教程,上边的都很规范。
package bbs.bccn.net;

import java.io.IOException;

public class JavaApplication
{
    public static void main(String[] args) {
         
        char ch = 0;
       System.out.print("请输入一个字符");
       try
       {   
           ch=(char)System.in.read();
           }catch(IOException e){
               
           }
       System.out.println("字符"+ ch +"的ASCII码值是"+(int)ch);// TODO code application logic here
   }
}

[ 本帖最后由 davidfly 于 2013-7-11 15:11 编辑 ]
----------------解决方案--------------------------------------------------------
回复 4楼 davidfly
正解
----------------解决方案--------------------------------------------------------
  相关解决方案