I am trying to use method overloading to find the area of a rectangle. Only thing is the values have to be entered by the user. But if it has to accepted from the user, shouldn't we know the datatype of his input? And if we do, then the purpose of overloading becomes useless, because I already know the datatype.
Can you guys help me out?
You can add onto this code:
import java.io.*;
import java.lang.*;
import java.util.*;
class mtdovrld
{
void rect(int a,int b)
{
int result = a*b;
System.out.println(result);
}
void rect(double a,double b)
{
double result = a*b;
System.out.println(result);
}
}
class rectarea
{
public static void main(String[] args)throws IOException
{
mtdovrld zo = new mtdovrld();
Scanner input= new Scanner(System.in);
System.out.println("Pleaser values:");
// Here is the problem, how can I accept values from user where I do not have to specify datatype and will still be accepted by method?
double a = input.nextDouble();
double b = input.nextDouble();
zo.rect(a,b);
}
}
You totally missed what I was saying. Yes, the DHCP server software is largely unchanged since the Windows 2000 Server version. My statement was somewhat of a joke, but I was saying that *IF* the DHCP server was written using today's Windows 11 *ERA* design philosophy, it would be a mess. Yes, even on the latest version of Windows Server it still uses the old software, but that wasn't really the point.
Ole Carl "One Plus One" Pei at it again. Surprised he didn't used the "invite" again.
The company had previously noted that it would need to sell at least 250,000 units to break even.
Question
Unto Darkness
I have got a problem.
I am trying to use method overloading to find the area of a rectangle. Only thing is the values have to be entered by the user. But if it has to accepted from the user, shouldn't we know the datatype of his input? And if we do, then the purpose of overloading becomes useless, because I already know the datatype.
Can you guys help me out?
You can add onto this code:
Link to comment
https://www.neowin.net/forum/topic/722390-java-method-overloading-while-accepting-input-from-a-user/Share on other sites
5 answers to this question
Recommended Posts