课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Modifying variables
- [Instructor] When writing our GrossPayCalculator program, we specify the values for hours and for pay rate. By doing this, we hard coded the values, meaning they will be the same every time this program is executed. However, for most variables, as the term implies, the value should vary. If we want this to be a program that anyone can use to calculate their gross pay, then we need to modify it. So instead of hard coding the value for hours, let's instead set the variable to a default value of zero and then ask the user to enter the number of hours worked. We can do this by saying System.out.println. How many hours did you work? When given a default value to a variable, this is known as initialization. We have initialized the hours variable with a value of zero. Now to read data from the user, we can use a scanner. We declare it as Scanner scanner equals new Scanner and inside parentheses, we'll say System.in.…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。