NETBEANS Java Basics 103 – Float Variables
PREREQUISITE
Download NetBeans from https://netbeans.org/downloads/
STEPS
1) Open the Startup Project.
Refer previous tutorial, http://javadevsteps.blogspot.com/2014/08/netbeans-java-basics-101-getting-started.html .
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.
No comments:
Post a Comment