Question: Please help me ASAP. Java codes P Q.7Loops: Examine the following code: for (int i = 5; i >= 1; i--) { System.out.print( < >);
Please help me ASAP. Java codes P
Q.7Loops:
Examine the following code:
for (int i = 5; i >= 1; i--) { System.out.print("<<"); for (int j = 5; j >= 1; j--) System.out.print((i * j) % 2 == 0 ? "-" : "*"); System.out.println(">>"); } Illustrate what would print:
Which lines of output have no dash characters?
Why is this the case?
Q9.
Spot and correct at least five errors in the following program. Start at the very beginning and move forward, looking for errors and assuming that your previous corrections apply, at that point.
Line #01: import java.util.random; Line #02: Line #03: public class 1stFloatClass { Line #04: Line #05: public static void main(String[] args) { Line #06: Line #07: Scanner scan = new Scanner(System.in); Line #08: double[] doubles = new double(); Line #09: int x = 0.0; Line #10: Line #11: for (i = 0; i < doubles.length(); i++) { Line #12: doubles[i] = I * 1.7; Line #13: System.out.print("Enter an int value: "); Line #14: x = scan.next(); Line #15: System.out.println("You entered: " + x); Line #16: System.out.println("Computer says: " + doubles{i} + x; Line #17: } Line #18: Line #19: }
Q10
10 Points
Grading comment:
Write a program that will...
Ask the user for the number of lines,
Store that value in the variable "lines" (already done for you!),
And print out each line.
To print a single line, you should do the following:
Repeatedly print a random character to the line. To do this, you can call the randChar() method. The number of characters printed should be equal to half of the line number. (Notice, in the case of line number 1, that no characters are printed. This is because integer division of 1 by 2 yields a result of zero.)
Skip to the next line.
As you might be able to tell, this is a "nested loop" problem!
NOTE: Remember the distinction between "print" vs. "println"
import java.util.Scanner; public class PrintingChars{ public static void main (String[] args) { Scanner scan = new Scanner(System.in); System.out.println("How many lines?"); int lines = scan.nextInt(); // For each line, between one and the // value of "lines" // Print out a number of characters // equal to one half the line # // Skip to the next line.
ENTER ANSWER HERE
} // You can call this method to get a random character private static char randChar(){ java.util.Random rGen = new java.util.Random(); return (char) (rGen.nextBoolean() ? randomIntInRange('a', 'z') : randomIntInRange('0', '9')); } private static int randomIntInRange(int low, int high) { int multiplier = high - (low - 1); return (int)(Math.random() * multiplier) + low; } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
