I posted this question before:

How would I put this into one program?
These are the directions:
Write a method that takes two parameters. If the first parameter is equal to second parameter. Multiply both and print result.

If the first parameter is less than the second parameter, add the two and print the result 10 times.

If the first parameter is greater than the second parameter, subtract the first parameter from the second and print the result 50 times.

I wrote the program and I just cant figure out how to print the results as a loop.

This is what I've got:
public class IfHomeworkRedo {

public static void two(int a, int b) {

if (a == b) System.out.println(a*b);

else if (a < b) {

for (int i = 0; i < 10; i++) {

System.out.println(a+b);

}
}

else {
b -= a;
}
}

public static void main (String[] args)

{

two(3, 3);

two(3, 4);

two(4, 3);

}

}

I posted some ideas on this for another student. See

http://www.jiskha.com/display.cgi?id=1435972699

http://www.jiskha.com/display.cgi?id=1436026108

You really need to learn how to use the net for the immense amount of help that is out there. You can find dozens of code snippets that will do exactly what you want. And the java documentation has many examples as well.

Hi Mr.Steve thank you for helping. I looked on the web and I looked at your responses to the other student. I'm still getting these errors on my code here:

public class IfHomeworkRedo {

2.

3.{

4.

5. public static void two(int a, int b) {

6.

7. if (a == b) System.out.println(a*b);

8.

9. else if (a < b) {

10.

11. for (int i = 0; i < 10; i++) {

12.

13. System.out.println(a+b);

14.

15. }

16. }

17.

18. else if (a > b) {

19.

20. for (int i = 0; i < 50; i++) {

21.

22. System.out.println(b-a);

23.

24.

25.

26. }

27.

28. }

29.

30.

31.

32.

33. public static void main (String[] args)

34.

35. {

36.

37. two(3, 3);

38.

39. two(3, 4);

40.

41. two(4, 3);

42.

43. }

44.

45.}

Can you help look at them?

Thanks.

Does the java compiler flag errors? It should say what they are.

If it runs, but is wrong, then welcome to the wonderful world of debugging.

Just eyeballing the code, its logic appears ok. What kinds of errors are you getting?

I think that the semicolon (;) should be deleted in your line:

if (a == b) System.out.println(a*b);

If you are using a decent java IDE, it should flag and highlight things like mismatched braces and wrong types.

To print the results as a loop, you can modify your code in the else branch where the first parameter is greater than the second parameter. Currently, you are subtracting the first parameter from the second, but you are not printing the result multiple times.

Here's how you can modify your code to print the result 50 times in a loop:

```java
else {
int result = b - a;

for (int i = 0; i < 50; i++) {
System.out.println(result);
}
}
```

With this modification, the program will subtract the first parameter from the second and store the result in the `result` variable. Then, it will print the `result` value 50 times using a for loop.

Here's the updated code:

```java
public class IfHomeworkRedo {

public static void two(int a, int b) {

if (a == b) {
System.out.println(a * b);
} else if (a < b) {
for (int i = 0; i < 10; i++) {
System.out.println(a + b);
}
} else {
int result = b - a;
for (int i = 0; i < 50; i++) {
System.out.println(result);
}
}
}

public static void main(String[] args) {

two(3, 3);
two(3, 4);
two(4, 3);
}
}
```

Now, when you run the program, it will print the results according to the given directions, whether it's multiplied, added multiple times, or subtracted multiple times.