I am fairly new to this site, and I need some help on this program I am working on for practice. I am trying to run an 'if-else' program that asks for the radius or diameter and then outputs the circumference. I've gotten to a pretty basic start, but even whilst looking all over the internet for answers, I'm still confused.
here is the code
import java.util.Scanner;
class Circumference
{
public static void main(String[] args)
{
double radius;
double diameter;
double c1 = (3.14 * (radius * radius));
double c2 = (3.14 * diameter);
Scanner in = new Scanner(System.in);
String answer = String.valueOf(1);
System.out.println("Do you have the radius, y/n?");
answer = in.nextLine();
{
if(answer.equalsIgnoreCase("y"))
{
System.out.println("Then give me the radius");
float radius = in.nextInt();
System.out.println("Circumference is : " + c1);
{
else if(answer.equalsIgnoreCase("n"))
{
System.out.println("Do you know the diameter then, y/n?");
string answer = in.nextLine();
{
else if(answer.equalsIgnoreCase("y"))
{
System.out.println("Then input the diameter");
float diameter = in.nextInt();
System.out.println("Circumference is : " + c2);
{
else if(answer.equalsIgnoreCase("n"))
{
System.out.println("Then find it");
}
}
}
}
}
}
}
}
}
}
When I try to change the string, it won't recognize it and say "can't change string to int", or that the radius in "c1" can't be found when executed.
All help is appreciated!
Aucun commentaire:
Enregistrer un commentaire