Question:
selection does not contain a main type- JAVA HELP?
runtomadic5
2013-02-03 16:32:32 UTC
can someone please tell me why it says selection does not contain a main type?

someone told me that i have to "remove main from wrapper class" but i dont know how to do it.

if anyone could help that would be awesome. thanks!
______________________________________…
import java.util.Scanner;

public class ComputeAndInterpretBMI {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

// Prompt the user to enter weight in pounds
System.out.print("Enter weight in pounds: ");
double weight = input.nextDouble();

// Prompt the user to enter height in inches
System.out.print("Enter height in inches: ");
double height = input.nextDouble();

final double KILOGRAMS_PER_POUND = 0.45359237; //Constant
final double METERS_PER_INCH = 0.0254; //Constant

//Compute BMI
double weightInKilograms = weight * KILOGRAMS_PER_POUND;
double heightInMeters = height * METERS_PER_INCH;
double bmi = weightInKilograms / (heightInMeters * heightInMeters);


//Display results
System.out.println("BMI is " + bmi);
if (bmi < 18.5)
System.out.println("Underweight");
else if (bmi < 25)
System.out.println("Normal");
else if (bmi < 30)
System.out.println("Overweight");
else
System.out.println("Obese");


// ##################################…
// ####################### That's all folks! ########################
// ##################################…



}

}
Three answers:
sappy16
2013-02-03 16:46:08 UTC
I think you basically just need to switch around these two statements:

public class ComputeAndInterpretBMI {

public static void main(String[] args) {



i.e.:

public static void main(String[] args) {

public class ComputeAndInterpretBMI {



...as main should be the first thing after import java.util.Scanner.



If that doesn't work, try removing the line:

public class ComputeAndInterpretBMI {



and its closing bracket at the end.
_Object
2013-02-04 00:47:49 UTC
You can't have main() inside that class like you do now. This cannot happen because main is the first thing the compiler looks for, and it will only see

class ComputeAndInterpretBMI

You need to simply cut the main function out of the class declaration. The class instance can only be created after main() is called, not before.

So take your class, separate it from main(), and put main somewhere else.
HMJava
2013-02-04 00:40:00 UTC
When you run this file run the COmptueAndInterPRetBMI.java and nothing else otherwise it will say that error.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...