JAVA help!!!!!!! loops?

1. Write a for loop that prints in ascending order all the positive multiples of 5 that are less than 175, separated by spaces.

2. Given a PrintWriter reference variable named output that references a PrintWriter object, write a statement that writes the string "Hello, World" to the file output streams to.

3. Write a for loop that prints the integers 0 through 39, separated by spaces.

4. Write a for loop that prints in ascending order all the positive integers less than 200 that are divisible by both 2 and 3, separated by spaces.

brilliant_moves2012-09-27T07:27:36Z

Favorite Answer

I've done the first question for you. Now have a go and see if you can do the others. Good luck! If you get stuck, post your code here, and we'll be able to help you.

public class ForLoop1 {
public static void main(String[] args) {
for (int i=5; i<175; i+=5) {
System.out.print(i+" ");
}
}
}

Camirr2016-10-28T01:49:53Z

Just had this for my CS hw. Hope this saves you a lot of annoyingness

for (int n = 5; n < 175 ; n ++) {
if ( n % 5 == 0)
{
System.out.print(n + " ");

The for loop starts at 5 via initialization, before going all the way up to 174 ( hence n < 175)

It goes up by 1s, and then the if statement says that if those integers get divided by 5 and have no remainder (Hence a multiple), that integer is to be printed.

I tried it with a blank else statement but it was refused, so just go simple here :).