Friday, August 15, 2014

NETBEANS Java Basics 102 – Double Variables

---
NETBEANS Java Basics 102 – Double Variables

PREREQUISITE

Download NetBeans from https://netbeans.org/downloads/ 

STEPS

1) Open the Startup Project.

package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        int first_number, second_number, answer;
        first_number = 10;
        second_number = 20;
        answer = first_number + second_number;
        System.out.println("Addition Total = " + answer );
    }  
}

2) Change Data Type to Double.

2-1 ) Change the keyword int to double.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        double first_number, second_number, answer;
        first_number = 10;
        second_number = 20;
        answer = first_number + second_number;
        System.out.println("Addition Total = " + answer );
    }  
}
2-2 ) Change the value assignments as follows.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        double first_number, second_number, answer;
        first_number = 10.5;
        second_number = 20.8;
        answer = first_number + second_number;
        System.out.println("Addition Total = " + answer );
    }  
}
2-3 ) Click Run button.
2-3) Outcome.

3) Perform Division Operation.


3-1 ) Change the value assignments as follows.

package firstproject;

public class FirstProject {

        public static void main(String[] args) {
            double first_number, second_number, answer;
            first_number = 10.5;
            second_number = 20.8;
            answer = first_number / second_number;
            System.out.println("Addition Total = " + answer );
        }  
}



3-2) Outcome.

REFERENCE

---

No comments:

Post a Comment