Write a Java statement or a set of Java statements to accomplish each of the tasks:

Print the integers from 1 to 20, using a for statement and the counter variable i. Assume that the variable i has been declared, but not initialized. Print only five integers per line. [Hint: Use the calculation i % 5. When the value of this expression is 0, print a newline character; otherwise, print a tab character. Assume that this code is an application. Use the System.out.println() method to output the newline character, and use the System.out.print('\t') method to output the tab character.]

```
for (i = 1; i <= 20; i++) {
System.out.print(i);

if (i % 5 == 0) {
System.out.println();
}
else {
System.out.print('\t');
}
}

```

Computer Science & Information Technology

You might also like to view...

List the six common work functions for system and application security design specified in the EBK.

What will be an ideal response?

Computer Science & Information Technology

Write program segments that accomplish each of the following:

a) Calculate the integer part of the quotient when integer a is divided by integer b. b) Calculate the integer remainder when integer a is divided by integer b. c) Use the program pieces developed in (a) and (b) to write a function that inputs an integer between 1 and 32767 and prints it as a series of digits, each pair of which is separated by two spaces. For example, the integer 4562 should print as follows: 4 5 6 2

Computer Science & Information Technology