if
-statement.
if
-statement inside a for-loop.
It would be nice to allow the user to enter data in a running Java program.
The code below allows the user to enter a
number from the interactions pane into a running Java program and then store the number in
the variable x
. Review the code below and then cut-and-paste this code
into a main program and class Lab12
.
Scanner s = new Scanner(System.in); // set up to read from the interactions pane System.out.print("Enter a number: "); // prompt for the first number int x = s.nextInt(); // read an integer
x
just to make sure the code above works. Compile and run it.
Remember you'll have to click on the interactions
tab in order to manually enter the number.
hello
?
y
and z
. Print the values to make sure it works.
if
-statement to your code from part I that prints
yes
if x
is
between 0 and 100 inclusive, otherwise print no
.
if
-statement that prints
negative
is x
is less
than 0, zero
if x
is equal to zero,
and positive
if x
is greater than 0.
if
-statement that uses the logical operator && as
well as the relational operators >
and
<
to print out the largest of the three values.
Example output might look like:
Variable z contains the largest value
count
at the end.
Write a program that prompts the user for an integer x
and then reads that many integers from the keyboard. Your program should
find the largest integer entered and the final average of all the integers
entered and print the results.