我想输入一个字符串,然后将其输出,但下面象输入字符或整数的方法却不行了,请问这是怎么回事?我如果想输入一个字符串,该如何写才最简单?谢谢!import java.io.*;class test_inputString
{
public static void main(String args[]) throws IOException
{
String str;
str=System.in.read(); //这句在编译时出错:不兼容的类型。我应该怎样写啊?谢谢大家了! System.out.println("str="+str);
}
}
{
public static void main(String args[]) throws IOException
{
String str;
str=System.in.read(); //这句在编译时出错:不兼容的类型。我应该怎样写啊?谢谢大家了! System.out.println("str="+str);
}
}
str=br.readLine();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
从Console读取要用BufferedReader
如果是GUI的 可以用JOptionPane的方法
import java.io.*;class test_inputString
{
public static void main(String args[]) throws IOException
{
int str;
str=System.in.read();
System.out.println("str="+(char)str);
}
}
java i/o跟c++的cin,cout比起来当然会觉得烦琐一点,
一般输入整数都是这样的
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
{
public static void main(String args[]) throws IOException
{
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
str=br.readLine();
// str=System.in.read(); //这句在编译时出错:不兼容的类型。我应该怎样写啊?谢谢大家了! System.out.println("str="+str);
}
}
str=br.readLine();
就行了
String str = args[0];
System.out.println(str);
}