NETBEANS Java Basics 102 – Double 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 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.
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.
No comments:
Post a Comment