getting an error in my area of circle result import java.util.Scanner; public cl
ID: 3618380 • Letter: G
Question
getting an error in my area of circle resultimport java.util.Scanner;
public class Main {
/**
* @param args the command linearguments
*/
public static void main(String[] args)
{
// TODO code applicationlogic here
Scanner input= newScanner (System.in);
System.out.println("enter the radius of a circle");
int radius=input.nextInt();
double p= 3.14;
int j= 5;
int ans=circlearea(p,j);
System.out.printf ("areaof circle is", ans);
}
public static int circlearea (double p,intradius)
{
int result;
double area=(p*radius*radius);
result= ans;
return result;
}
}
Explanation / Answer
It needed alot of editing but here ya go! You had precision errors and you declared the method as a intinstead of a double. import java.util.Scanner; public class Main { /** * @param args the command linearguments */ //http://javacoder.webs.com //http://javacoder.webs.com public static void main(String[] args) { // TODO code applicationlogic here Scanner input= newScanner (System.in); System.out.println("enter the radius of a circle"); int radius=input.nextInt(); double p= 3.14; int j= 5; double ans=circlearea(p,j); System.out.printf ("areaof circle is " + ans); } public static double circlearea (double p,intradius) { double result; double area =(p*radius*radius); result = area; return result; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.