Square Root (Integral) Problem Statement
Given a number N
, calculate its square root and output the integer part only.
Example:
Input:
18
Output:
4
Explanation:
The square root of 18 is approximately 4.24. The integer part is 4.
Constraints:
0 ≤ N <= 108
Kamakshi Dhankar
2y
import java.util.Scanner ;
public class Main {
public static void main(String[] args) {
// Write your code here
int i = 1 , result =1 ;
Scanner s = new Scanner(System.in);
int N = s.nextInt();
while(result<=N) {
i++ ;
result = i*i ;
}
System.out.println( i- 1 );
}
}
Help your peers!
Add answer anonymously...
Top Oracle Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Oracle Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app