File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Program Error,Thanks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Program Error,Thanks" Watch "Program Error,Thanks" New topic
Author

Program Error,Thanks

Jiali Yang
Greenhorn

Joined: Mar 20, 2006
Posts: 3
import java.io.*;
public class MultiplyNumbers{
public static void main(String[] args)
throws java.io.IOException{
String s1;
String s2;
Double num1,num2,product;

InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);

System.out.println("Enter a number: ");
s1=br.readLine();
num1=Double.parseDouble(s1);

System.out.println("Great! Now enter another number: ");
s2=br.readLine();
num2=Double.parseDouble(s2);

product=num1*num2;
System.out.println(num1+" times "+num2+" is "+product);
}
}

以下是错误提示:
MultiplyNumbers.java:14: incompatible types
found : double
required: java.lang.Double
num1=Double.parseDouble(s1);
^
MultiplyNumbers.java:18: incompatible types
found : double
required: java.lang.Double
num2=Double.parseDouble(s2);
^
MultiplyNumbers.java:20: operator * cannot be applied to java.lang.Double,java.lang.Double
product=num1*num2;
^
3 errors


<a href="http://www.ychda.cn" target="_blank" rel="nofollow">http://www.ychda.cn</a>
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Welcome to JavaRanch!

My guess is that you want num1, num2, and product to be of type double (with a lowercase 'd') instead of type Double (with an uppercase 'D').

(The uppercase Double is a wrapper class.)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Kj Reddy
Ranch Hand

Joined: Sep 20, 2003
Posts: 1704
Double.parseDouble() method returns primitive data type double and not Double.
So declare num1,num2,product as double instead of Double as:

double num1,num2,product;;
Jiali Yang
Greenhorn

Joined: Mar 20, 2006
Posts: 3
Thank you for your help!
I find JavaRanch yesterday,and I like the website very much.
I'm from China,so my English is poor,but I will work hard to find useful message here.

ychda
Taiyuan,China
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program Error,Thanks