Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
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.
2 Answers
- brilliant_movesLv 79 years agoFavorite 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+" ");
}
}
}
Source(s): Experience - 5 years ago
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 :).