How can I solve Exception in thread main java lang NullPointerException error

0 votes

I am having a problem at a Java program. Exception in thread "main"

java.lang.NullPointerException
at twoten.TwoTenB.<init>(TwoTenB.java:29)
at javapractice.JavaPractice.main(JavaPractice.java:32)
Java Result: 1 

is the error that I'm getting. I could really use some help, since i am stuck hours on this spot...

package twoten;

import java.util.Scanner;

public class TwoTenB {

public TwoTenB() {
    double percentage;
    double a[] = null;
    double total = 0;
    double var;
    System.out.print("\tRESULT\n\n");
    Scanner scan = new Scanner(System.in);
    //double[] mark = new double[7];
    for (int i = 0; i < 7; i++) {

        System.out.print("\nMarks in subject " + (i + 1) + "\t:\t");
        var = scan.nextDouble();

        a[i] = var;

        total = total + a[i];
       //percentage = first * second * third * fourth * fifth * sixth * seventh * 100 / 700;
    }

    percentage = total * 100 / 700;

    if (a[0] > 35 && a[1] > 35 && a[2] > 35 && a[3] > 35 && a[4] > 35 && a[5] > 35 && a[6] > 35 && percentage > 35) {
        if (percentage >= 60) {
            System.out.print("\nCongratulation!!! you've got FIRST dividion\n");
        } else if (percentage >= 45 && percentage < 60) {
            System.out.print("\nCongratulation!!! you've got SECOND dividion\n");
        } else if (percentage >= 35 && percentage < 45) {
            System.out.print("\nCongratulation!!! you've got THIRD dividion\n");
        }
    } else {
        System.out.print("\nSORRY!!! you've FAILED\n");
    }
    }
}
Sep 20 in Java-Script by Tejashwini
• 540 points
12 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java-Script

0 votes
0 answers

How can I solve "java.lang.NoClassDefFoundError"?

I've tried both the examples in Oracle's Java ...READ MORE

Sep 20 in Java-Script by Tejashwini
• 540 points
13 views
0 votes
0 answers

Exception in thread "main" java.util.NoSuchElementException

Whenever I run this, the chooseCave() function works fine ...READ MORE

Sep 20 in Java-Script by Tejashwini
• 540 points
17 views
0 votes
1 answer

How can I rename a database column in a Ruby on Rails migration?

Hello @kartik, Try using this: rename_column :table, :old_column, :new_column You'll ...READ MORE

answered Jul 24, 2020 in Java-Script by Niroj
• 82,780 points
859 views
0 votes
1 answer

How can I specify a local gem in my Gemfile?

Hello @kartik, In order to use local gem ...READ MORE

answered Jul 24, 2020 in Java-Script by Niroj
• 82,780 points
1,745 views
0 votes
1 answer

How can I get query string values in JavaScript?

Hello @kartik, You don't need jQuery for that ...READ MORE

answered Jul 27, 2020 in Java-Script by Niroj
• 82,780 points
360 views
0 votes
1 answer

How can i insert data in relation table using model?

Hello @Alisha, Try to work using the model ...READ MORE

answered Aug 24, 2020 in Java-Script by Niroj
• 82,780 points
328 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 64,784 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
6,860 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
14,671 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
3,206 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP