JAVA solutions to writting java method

For questions click here

1. answer
public void powersOfTwo ()
{
int power = 1;
for (int count=1; count <= 10; count++)
{
power *= 2;
System.out.println (power);
}
}

2. answer
public void alarm (int num)
{
for (int count=1; count <= num; count++)
System.out.println ("Alarm!");
}

3.answer
public int sum100 ()
{
int sum = 0;
for (int count=1; count <= 100; count++)
sum += count;
return sum;
}

4. answer
public int sumRange (int low, int high)
{
int sum = 0;
for (int count=low; count <= high; count++)
sum += count;
return count;
}

5. answer
public int maxOfTwo (int num1, int num2)
{
int result = num1;
if (num2 > num1)
result = num2;
return result;
}

6. answer
public boolean larger (double num1, double num2)
{
return (num1 > num2);
}

7. answer
8.answer
9. answer
10. answer
11. answer
12. answer
13.answer
14. answer
15. answer
Previous
Next Post »