Topic: 问一个关于import的问题

  Print this page

1.问一个关于import的问题 Copy to clipboard
Posted by: dalipoo
Posted on: 2005-04-04 13:00

我按照一本书的内容写了以下程序,求一个圆的面积,半径可自己设定,编译时有如下错误说明,请帮忙看一下。先谢谢了!
我假期里看了一些内容,但没有自己调试过,是个初学者,请高手指教了。

ComputeArea.java:24:‘class’or'interface'expected
import java.io.*;
^
1 error
以上是错误说明。以下是程序部分:
//ComputeArea.java:Compute the area of circle
public class ComputeArea
{
//Main method
public static void main(String[] args)
{
double radius;
double area;

//Prompt the user to enter radius
System.out.print("Enter radius:");
radius=MyInput.readDouble();

//Computer area
area=radius*radius*3.14159;

//Display results
System.out.print("The area for the circle of radius"+radius+"is"+area);
}
}

//MyInput.java:Contain the method for reading int,double,and string values from the keyboard

import java.io.*;

public class MyInput
{

// Read a string from the keyboard
public static String readString()
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in),1);

//Declare and initialize the string
String string=" ";

//Get the string from the keyboard
try
{
string=br.readLine();
}
catch(IOException ex)
{
System.out.println(ex);
}

//Return the string obtained from the keyboard
return sring;
}

//Read an int value from the keyboard
public static int readInt()
{
return Interger.parseInt(readString());
}

//Read an double value from the keyboard
public static double readDouble()
{
return Double.parseDouble(readString());
}
}

2.Re:问一个关于import的问题 [Re: dalipoo] Copy to clipboard
Posted by: wddodo
Posted on: 2005-04-04 15:53

如下代码可以运行:
import java.io.*;
public class ComputeArea
{
//Main method
public static void main(String[] args)
{
double radius;
double area;

//Prompt the user to enter radius
System.out.print("Enter radius:");
radius=MyInput.readDouble();

//Computer area
area=radius*radius*3.14159;

//Display results
System.out.print("The area for the circle of radius"+radius+"is"+area);
}
}

//MyInput.java:Contain the method for reading int,double,and string values from the keyboard

class MyInput
{

// Read a string from the keyboard
public static String readString()
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in),1);

//Declare and initialize the string
String string=" ";

//Get the string from the keyboard
try
{
string=br.readLine();
}
catch(IOException ex)
{
System.out.println(ex);
}

//Return the string obtained from the keyboard
return string;
}

//Read an int value from the keyboard
public static int readInt()
{
return Integer.parseInt(readString());
}

//Read an double value from the keyboard
public static double readDouble()
{
return Double.parseDouble(readString());
}
}

3.Re:问一个关于import的问题 [Re: dalipoo] Copy to clipboard
Posted by: lu_wei
Posted on: 2005-04-04 20:06


4.Re:问一个关于import的问题 [Re: dalipoo] Copy to clipboard
Posted by: dalipoo
Posted on: 2005-04-04 22:34

谢谢楼上的两位的指教,wddodo的程序可以通过!

5.Re:问一个关于import的问题 [Re: dalipoo] Copy to clipboard
Posted by: wmgreat
Posted on: 2005-04-05 09:32

唉!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923