Friday, August 15, 2014

NETBEANS Java Basics 103 – Float Variables

---
NETBEANS Java Basics 103 – Float 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 Float.

2-1 ) Change the keyword int to float.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        float 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) {
        float 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) NetBeans responds with error message.
2-4 ) Change the value assignments as follows.
package firstproject;
public class FirstProject {
    public static void main(String[] args) {
        float first_number, second_number, answer;
        first_number = 10.5f;
        second_number = 20.8f;
        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) {
        float first_number, second_number, answer;
        first_number = 10.5f;
        second_number = 20.8f;
        answer = first_number / second_number;
        System.out.println("Addition Total = " + answer );
    }  
}
3-2) Outcome.

REFERENCE

---

No comments:

Post a Comment