The Artima Developer Community
Sponsored Link

Java Answers Forum
why is it not working?????

2 replies on 1 page. Most recent reply: Jun 15, 2010 11:02 PM by bhavna raghuvanshi

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
bhavna raghuvanshi

Posts: 6
Nickname: bhavna13
Registered: Jun, 2010

why is it not working????? Posted: Jun 14, 2010 11:14 PM
Reply to this message Reply
Advertisement
plz someone help me.
i am not able to understand why evaluate function is not getting called

import java.util.Scanner;
import java.io.*;
interface Function
{
public int evaluate(int x);
}

public class Half implements Function
{
int parameter , value,x;

public static void main ( String args[] )
{
System.out.println("inside main");
Half a= new Half();
a.evaluate(int x);
}
public int evaluate(int x)
{
System.out.println("inside evaluate");
Scanner scan = new Scanner(System.in);
System.out.println("Enter an integer :");
parameter= scan.nextInt();
System.out.println("hi");
value=parameter/2;
System.out.println ("The value is :" + value);
return value;
}


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: why is it not working????? Posted: Jun 15, 2010 12:52 AM
Reply to this message Reply
Change the line:
a.evaluate(int x);
to
a.evaluate(x);
That will get rid of the error that you are seeing but it will also uncover another error. The variable x hasn't been initialised (or entered by the user). You need to give a value to x or get a value for x from the user before calling the evaluate(int) function.

bhavna raghuvanshi

Posts: 6
Nickname: bhavna13
Registered: Jun, 2010

Re: why is it not working????? Posted: Jun 15, 2010 11:02 PM
Reply to this message Reply
thanks....
my work is done

Flat View: This topic has 2 replies on 1 page
Topic: urgent help pls..... Previous Topic   Next Topic Topic: how to print an histogram?????

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use