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...
Oracle Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter