java怎么 输入输出中文

/*
* Main.java
*
* Created on 2007年4月14日, 下午5:15
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package javaapplication1;

/**
*
* @author hch
*/
public class Main {

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main (String[] args) throws Exception
{
// TODO code application logic here
int 中1=System.in.read();
int 中2=System.in.read();
System.out.print((char)中1);
System.out.print((char)中2);
}

}
/*
我打算输入一个中文字符并显示,于是写了上面的程序,但结果并不如我想象的输出中文字符,显示了两个乱码,所以想请问大家怎么将输入中文字符并输出
*/
回 天之魔神:定义成字符型要用什么输入函数,用read()会出错

看来是个Java初学者,估计你对Java的流概念不是很清楚啊,Java的输入输出都是通过数据流来完成的,看看下面的代码吧。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] chars = new char[2];
try {
br.read(chars);
System.out.println(chars);
}
catch(IOException ioe) {
ioe.printStackTrace();
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-04-14
<script language="javascript">
var a
function aa(){
document.write("想输出的汉字")
}
</script>
<input type=button value=单击 onclick="aa()">
第2个回答  2007-04-14
你这两个变量要定义成 char类型的

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网