2 Replies - 374 Views - Last Post: 22 January 2013 - 11:47 AM Rate Topic: -----

#1 am0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 22-January 13

The operator * is undefined for the argument

Posted 22 January 2013 - 11:30 AM

Hello, I'm new to this website, and new to programming.
I'm trying to write a simple code that will multiply height and width(Excuse my English, It's not my native language)
But I'm getting the error "The operator * is undefined for the argument"
Here's my code
import java.util.Scanner;
class Calc {

	public static void main(String args[]){
		
		
		double answer;
		System.out.println(" enter width");
		Scanner width1 = new Scanner(System.in);
		
		System.out.println("enter height");
			Scanner height1 = new Scanner(System.in);	
			answer = height1 * width1;
			
			
	}
}


Any suggestions?

Is This A Good Question/Topic? 0
  • +

Replies To: The operator * is undefined for the argument

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: The operator * is undefined for the argument

Posted 22 January 2013 - 11:37 AM

"The argument(s)" in this case are two Scanner objects. The error is telling you that multiplying (how we would typically interpret the '*' operator) is not defined for two Scanner objects.

You'll have better luck if you change your idea to:
public static void main( String[] args )
{
    Scanner input = new Scanner( System.in );
    
    double answer;
    System.out.println(" enter width");
    double width1 = input.nextDouble();
    
    System.out.println("enter height");
        double height1 = input.nextDouble();   
        answer = height1 * width1;
        
    System.out.println( "The answer is: " + answer );
    
    input.close();
}

Was This Post Helpful? 3
  • +
  • -

#3 am0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 22-January 13

Re: The operator * is undefined for the argument

Posted 22 January 2013 - 11:47 AM

Thank you, Greg.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1