Chapter 6 Methods Solutions
Chapter 6 Methods Solutions
import java.util.Scanner;
int d = max(a1,b1,c1);
System.out.println("The maximum of three numbers = "+d);
}
Output –
Enter three numbers
5
6
4
The maximum of three numbers = 6
Question8 –
}
}
Output –
= = = = = = = = = = RESULT CARD = = = = = = = = = = = =
Name: Laksh
Roll Number: 121
Marks Obtained
Maths: 78
English: 89
Hindi: 76
Punjabi: 65
Science: 87
Total marks obtained: 395
Percentage: 79.0
Grade: B
Question9 –
c=sub(a, b);
System.out.println("The difference of two numbers="+c);
c=multi(a, b);
System.out.println("The product of two numbers="+c);
c=division(a, b);
System.out.println("The quotient of two numbers="+c);
c=modulus(a, b);
System.out.println("The remainder obtained after dividing two numbers="+c);
Output –
a=6
b=4
The sum of two numbers=10
The difference of two numbers=2
The product of two numbers=24
The quotient of two numbers=1
The remainder obtained after dividing two numbers=2
Question10 –
System.out.println("Base="+b+", height="+h);
a=area1(b, h);
System.out.println("The area of the triangle = "+a);
}
Output –
Base=12, height=5
The area of the triangle = 30.0
lengths of sides = 17, 8, 15
The area of the triangle = 60.0
Question11 –
}
}
Output –
The area of the square = 25.0
The area of the rectangle = 30.0
The area of the circle = 28.259999999999998
Question12 –
import java.util.Scanner;
prime(a);
evenOrOdd(a);
}
}
Output –
Enter a number = 31
31 is a prime number
31 is an odd number
Question13 –
import java.util.Scanner;
while(x<n)
{
System.out.print(x+" ");
z=x+y;
x=y;
y=z;
}
fibo(a);
}
}
Output –
enter a number to print fibonacci series less than it = 24
0 1 1 2 3 5 8 13 21
Question14 –
import java.util.Scanner;
System.out.println("Enter 5 numbers:");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
int e = sc.nextInt();
}
}
Output –
Enter 5 numbers:
5
8
6
3
9
The average of 5 numbers: 6.2