Home > Back-end >  JAVA a subroutine
JAVA a subroutine

Time:10-25

Design a child function, according to a given radius of integer data, calculate the area of a circle (return parameter is real), is the main function in assignment statement calls to display the results for an argument, you can just write the core algorithm,

Here is to write their own code, but the code demands sub function results of real Numbers, hope leaders help
Package zz0224;

Public class SSS {
Private static final double PI=3.14;
Public static int the add (double r)
{
Return (int) (PI * r * r);
}
Public static void main (String [] args) {
Int r=4,
Sum=0;
Sum=add (r);
System. The out. Print (" the area of a circle="+ sum);
}
}


?

CodePudding user response:

The return value is written is wrong, if you want to return with the decimal number, can't return an int, to return to double

CodePudding user response:

reference 1st floor timesong wind xiao xi response:
return values are wrong, if you want to return with the decimal number, can't return an int, to return to a double

Can you help to change correct , can't the

CodePudding user response:

refer to the second floor?????? Response:
Quote: refer to 1st floor timesong wind xiao xi response:
return values are written in the wrong, if you want to return with decimal number, can't return an int, to return to a double

Can you help to change correct , can't the

 
Public class SSS {

Private static final double PI=3.14;

Public static double add (double r) {
Return PI * r * r;
}

Public static void main (String [] args) {
Int r=4;
Double sum=add (r);
System. The out. Print (" the area of a circle="+ sum);
}
}

CodePudding user response:

Your thoughts can ah, just type is wrong, the following point is to change
Public static double the add (int r)
Double sum=0

CodePudding user response:

reference 1st floor timesong wind xiao xi response:
return values are wrong, if you want to return with the decimal number, can't return an int, to return to a double

How to accept your advice, I'm sorry didn't find a place to adopt, also please let us know

CodePudding user response:

reference 5 floor?????? Response:
Quote: refer to 1st floor timesong wind xiao xi response:
return values are written in the wrong, if you want to return with decimal number, can't return an int, to return to a double

How to accept your advice, I'm sorry didn't find a place to adopt, also please let us know

None of them have been stick, I don't know you should stick to know it
  • Related