刚开始学习java,请问java中输入方法是read()吗?为什么下面的程序编译时显示read()方法不对那?
public class P {
public static void main(String args[])
{double a,b;
System.out.println("input a number please:");
System.in.read(a);
b=Math.sqrt(a);
System.out.println("平方根为"+b);
}
}
public class P {
public static void main(String args[])
{double a,b;
System.out.println("input a number please:");
System.in.read(a);
b=Math.sqrt(a);
System.out.println("平方根为"+b);
}
}
解决方案 »
- 请教,关于Vector中嵌套Vector
- 快来看一下,帮助一下新手吧谢谢
- java一处出错大虾看看
- 在applet中如何关闭IE窗口?
- 如何填充自己绘制的图形?
- 求助:各位前辈,高手们,怎样将JAVA工程生成一个可执行文件(.exe)呢?
- Image Graphics 的区别,(或者推荐相关网站)
- 困惑很久的问题,一个实体BEAN只能对应一个TABLE吗?如果有几百个TABLE,难道要写几百个实体BEAN?
- 能不能给我一些输出输入处理的例子呀
- 请问,用在java_applet中怎么实现一幅图片的旋转?怎么控制转动的速度?
- 一个随机排列的问题
- 在java中如何以二进制的形式打开文档,并依次读取字节?!!!!
你可以把double值作为String读进来,然后将String转换为double,这个很简单的
import java.io.*;public class StringInput {
public static void main(String args[]) {
try {
BufferedReader in = null;
in = new BufferedReader(new InputStreamReader(System.in)); // 从键盘接收了一个字符串的输入,并创建了一个字符输入流的对象
String s = null;
s = in.readLine();// 从输入流in中读入一行,并将读取的值赋值给字符串变量s,然后将s转换为double
} catch (IOException e) {
System.out.println(e);
}
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;public class P{
public static void main(String args[]) throws IOException
{
double a=0;
double b=0;
System.out.println("input a number please:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
a = Double.parseDouble(br.readLine());
b=Math.sqrt(a);
System.out.println("平方根为"+b);
}
}
可以用read的 ····public class Test {
public static void main(String args[]) throws Exception
{double a=0,b;
System.out.println("input a number please:");
byte[] buf=new byte[100];
int len=System.in.read(buf);
String str=new String(buf,0,len);
a=Double.parseDouble(str);
b=Math.sqrt(a);
System.out.println("平方根为"+b);
}
}