A good answer might be:There are some syntax errors: long good-by ; // bad identifier: "-" not allowed short shrift = 0; // OK double bubble = 0, toil= 9, trouble = 8 // missing ";" at end. byte the bullet ; // bad identifier: can't contain a space int double; // reserved word char thisMustBeTooLong ; // OK in syntax, but a poor choice for a variable name int 8ball; // can't start with a digit |
Example ProgramHere is another example program, containing several variable declarations.
The character * means multiply.
In the program, (hoursWorked * payRate) means to
multiply the number stored in hoursWorked
by the number stored in payRate.
When it follows a character string,
+ means to
add characters to the end of the character string.
So The program illustrates anHours Worked: 40 pay Amount : 400.0 tax Amount : 40.0 Important Idea: To use the value stored in a variable, just use the name of the variable.So, for example, in the first System.out.println statement, the variable hoursWorked was used. This means "go get the value inside hoursWorked and use that value here. Remember that if you want to run these programs, you can "copy" them from your www browser, "paste" them into the window of Notepad, and proceed as usual. (See the chapter "Running Example Programs without Typing" in these Notes.) If you are on a Unix system you can do similar things with your browser and editor window. |
QUESTION 7:Why did the program print the first "40" without a decimal point, but printed the second one with a decimal point as "40.0" ? Click Here after you have answered the question |