If you prefer to use another environment (such as Eclipse or Sublime), that’s fine. On the first three assignments, you’ll need to enter command-line arguments. After that, you will need to add our textbook libraries stdlib.jar to your classpath and access to the command line (for redirection of standard input and standard output).
CMYKtoRGB
are four real numbers between 0.0 and 1.0 (and not, say, two arbitrary strings).
hello.zip
.
hello
(the .zip extension is automatic).
zip hello.zip *.java
.
public
, static
,
void
, class
, and main
during this course.
javac: file not found: HelloWorld.java
when
I type the command javac HelloWorld.java
. What did I do wrong?
HelloWorld.java
in the current directory.
Could not find or load main class HelloWorld.java
when
I type the command java HelloWorld.java
. What did I do wrong?
javac
, you use the filename with the .java
extension
(e.g., HelloWorld.java
).
When executing with java
, you use the class name, which has no
.java
extension (e.g., HelloWorld
).
true
or false
without an if–else statement?b
is a boolean
variable, then
System.out.println(b)
prints true
or false
,
according to its value.
a * a
.
In Java, the ^
operator means exclusive or, not exponentiation.
You could use Math.pow(a, 2)
; however, that converts a
to a double
before squaring, which is considered poor style.
arePositive
to be true
if a, b, and c are all positive, and false
otherwise.
Then, you can use this boolean variable (and others) to define a boolean variable isRightTriangle
that checks for valid right triangles.
int
?Math
library functions should I use?Math.toRadians()
,
Math.sqrt()
,
Math.pow()
,
Math.sin()
,
Math.cos()
, and
Math.asin()
are particular relevant here.
int
value?
Math.round(x)
to round x
to the nearest long
value;
then cast the result to an int
.
If there is a tie, Math.round()
will round toward positive infinity.