Hi guys this program is giving a runtime error in Java…The code is full correct and no compilation error?

import java.io.*;

public class JavaApplication

{

public static void main() throws IOException,NumberFormatException

{

BufferedReader bis=new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Please enter ur sex or gender”);

char g=(char)bis.read();

System.out.println(“Enter ur age”);

int age=Integer.parseInt(bis.readLine());

int total=;

if(g==’M’ || g==’m’)

{

if(age>)

{

total=+;

}

else if(age>)

{

total=;

}

System.out.println(“Gender= ” + g +” and age = ” + age + ” and ur pension = ” + total);

}

else if(g==’F’ || g==’f’)

{

if(age>)

{

total=;

}

else if (age>)

{

total=+;

}

System.out.println(“Gender= ” + g + ” and age = ” + age + ” and ur pension = ” + total);

}

}

}

✅ Answers

? Favorite Answer

  • Try

    char g = bis.readLine().charAt();

    Well actually the code should be

    System.out.println(“Please enter your sex or gender”);

    String input = bis.readLine();

    while (input.length() == || input.length() > || (!input.equalsIgnoreCase( “m”) && !input.equalsIgnoreCase( “f”))) {

    System.out.println( “An error was detected in your input”);

    System.out.println(“Please enter your sex or gender”);

    input = bis.readLine();

    } //End while

    char g = input.charAt();

    Have fun.

  • Method invokation is wrong

    import java.io.*;

    public class JavaApplication {

    public static void main(String[] args) {

    try {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    System.out.print(“Enter your sex or gender: “);

    String gender = br.readLine();

    System.out.print(“nEnter your age: “);

    int age = Integer.parseInt(br.readLine());

    int total = ;

    if (gender.equalsIgnoreCase(“M”)) {

    if (age > ) {

    total = + ;

    }

    else if (age > ) {

    total = ;

    }

    }

    if (gender.equalsIgnoreCase(“F”)) {

    if (age > ) {

    total = ;

    }

    else if (age > ) {

    total = + ;

    }

    }

    System.out.println(“Gender = ” + gender + ” and age = ” + age + ” and your pension = ” + total);

    }

    catch (Exception ex) {

    System.err.println(ex.toString());

    }

    }

    }

  • Your main declaration is wrong:

    public static void main() throws IOException,NumberFormatException

    should be:

    public static void main(String[] args) throws IOException,NumberFormatException

    There may be other errors, but that is the most obvious. Good luck!

    See also  Help with C++ Programming ? Someone please explain me this simple C++ inheritence program step by step ?

    Source(s): Experience

  • Other Related Questions

    Learning Visual Basic ?

    Answers Favorite AnswerTry using "System.Diagnostics.Process. GetProcessesByName( "iwmp" ).Length > " for your check.

    Microsoft Office word Fast answer needed its urgent?

    Answers Favorite AnswerTry this:http://www.techsupport.com///microsoft-wo...Here is another thread re: the same issue with instructions:http://www.pcreview.co.uk/forums/modification-not-...http://www.techsupport.com///microsoft-wo...http://support.microsoft.com/kb/http://answers.microsoft.com/en-us/office/forum/of...

    Can I download a whole city android google maps?

    Answers Favorite Answer:) Yes!!!Interesting question. I wonder why it has blocked in this way especially considering that Google Earth is very detailed and has good maps of Israel.

    What is meant by ROM ? Explain in simple but elaborate terms.What about mobile ROM’s?

    Answers Favorite AnswerHi Diva below is a link that will give a simple answer.http://wiki.answers.com/Q/What_does_ROM_stand_for_...Hope this helps.Source(s): Experience and wiki answers.ROM is Read only memory. i.e data can write only once.There two types of ROM..ROM.PROMThe difference between ROM and PROM.that is ROM is programmed during manufacturing it means data stored by manufacturing company.PROM is blank memory that a user programmable memory.user can store content on PROM.both ROM and PROM are Read only memory Data can write only once.and its not possible to write so many time.Memories of PROM and ROM are Non-volatile in nature. Its that stored informations can retain even power goes off.

    Leave a Comment