Using NetBeans Variable declarations & assignments

draindecorumΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 5 χρόνια και 3 μήνες)

278 εμφανίσεις

Using NetBeans
Advantages of using NetBeans
 No need to deal with creating individual les in Notepad
 No need to run multiple programs (Notepad for writing,Windows Explorer for modifying
les,Command Prompt for compiling and executing).All your writing,compiling,executing,
and le management happens in a single program.
 It provides several powerful features that would otherwise be very time-consuming.
Running NetBeans
 Start Netbeans.
 Select\New Project"
{ Uncheck\create main class"
 Select\New File"of type\Java Main Class"
 You can delete the template code and write your own,or you can type in the code inside the
main() method.
 When you are ready to compile and execute your program,select\Run > Run File > Run
File"or just hit Shift - F6.
 A project can have as many les as you want.So when creating your programs,you can
either:
{ create a le for each program inside the same project,OR
{ create a new project (and inside it,a new le) for each program
{ For now choose the rst option.
Variable declarations & assignments
Variables are delcared by this format (syntax):
type variable
1
;variable
2
;:::;
Examples:
int numberOfEggs;
double principalAmount,interestRate,totalAmount;
char answer;
1
Variables are assigned values by using an equation{like syntax:
variable = expression
An expression may be a constant value (e.g.,23,`A',120.21) or an arithmetic expression (23 * 2.0,
2 * numberOfEggs).Examples:
principalAmount = 230.50;
score = numberOfCards + handicap;
The names are variables.The expression is rst evaluated and then the variable is assigned the
value of the expression.
A variable can occur on both sides of an assignment:
count = count + 10;
We can also combine declaration and assignment.
Example:
int number = 10;
double height = 12.3;
char answer =`Y';
Exercise.Write a program starting with two variables,number
1
and number
2
of type int.Mul-
tiply them and store the result in a new variable result.Print out c's value.
Exercise.Write a program with two variables
2