Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS 214 Lab 4: Java Exercise CS 214 Lab 4: Java Exercise Begin by using a text editor to edit the file LogTable.java. Take a moment to study it, to see how it implements our basic algorithm. To generate our table of logarithms, we need to use a Java repetition statement, of which there are three: Statement ::= WhileLoop | DoLoop | ForLoop WhileLoop ::= while (Expression) Statement DoLoop ::= do Statement while (Condition); ForLoop ::= for (Expression;Expression;Expression) Statement Our particular problem is an example of a counting problem, in which we want to count from start to stop by intervals of increment, displaying the value of count and its logarithm. For counting problems, the Java for loop provides the most convenient notation, but you'll practice that in this week's project so we'll use a while loop today. When execution reaches a for loop, the first Expression is evaluated, usually providing for initialization of a loop-control variable (i.e., count). If the second Expression evalautes to true (non-zero), then Statement is executed, after which the third Expression is executed. The second Expression thus serves as a continuation-condition for the loop, with the third Expression serving as an increment-expression. (Any or all of these Expressions can be omitted, if the second Expression is omitted, true is taken as a default, providing an indeterminate loop construct.) Output in Java is accomplished via the usual output expression, while to compute the base-10 logarithm of count, we can use the log10() method. This method is part of the Math class, which is included in the java.lang package. The java.lang package is included implicitly in all Java programs, so you do not need to used the import command to make the class or method available. Drawing on these observations, write a while loop that generates the required table. Compile and test your code for correctness; then use script to create a script.java file in which you cat your file, compile it, and show that it works correctly for the input values 1, 10, 0.5. That concludes the Java part of the lab. Calvin > CS > 214 > Labs > 04 > Java This page maintained by Joel Adams