Skip to content

Commit d2abfab

Browse files
committed
Completed question on methods
1 parent 281c8fb commit d2abfab

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

13_Methods/Question4.class

1.31 KB
Binary file not shown.

13_Methods/Question4.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
public class Question4 {
3+
public static void operation(int a, int b) {
4+
System.out.println("Min of (" + a + "," + b + ") : " + Math.min(a, b));
5+
System.out.println("Max of (" + a + "," + b + ") : " + Math.max(a, b));
6+
System.out.println("Sqaure root of " + b + " : " + Math.sqrt(b));
7+
System.out.println(b + " to the power " + a + " = " + Math.pow(b, a));
8+
System.out.println(Math.abs(-5.242));
9+
10+
}
11+
12+
public static void main(String[] args) {
13+
operation(3, 2);
14+
}
15+
}

13_Methods/Question5.class

532 Bytes
Binary file not shown.

13_Methods/Question5.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// WAP to compute the sum of the digits in an integer.
2+
3+
public class Question5 {
4+
public static int sum(int num) {
5+
int sum = 0;
6+
while (num > 0) {
7+
int rem = num % 10;
8+
sum += rem;
9+
num /= 10;
10+
}
11+
return sum;
12+
}
13+
14+
public static void main(String[] args) {
15+
System.out.println(sum(811));
16+
}
17+
}

0 commit comments

Comments
 (0)