...

x

Write a program **to find the nearest perfect square of a given number**. Assume that the given number is always greater than 2.

Input (Integer) | Output (Integer) |
---|---|

`3` |
`4 (Since 3 is between 1 and 4, but nearer to 4 than 1)` |

`9` |
`9 (Since 9 it is a perfect square)` |

`10` |
`9 (Since 10 is between 9 and 16, but nearer to 9 than 16)` |

`23` |
`25 (Since 23 is between 16 and 25, but nearer to 25)` |

`17` |
`16 (Since 17 is between 16 and 25, but nearer to 16)` |

```
class FindNearestPerfectSquare
```{ public static void main(String s[])

{

int input = 23;

int result = findNearestPerfectSquare(input);

System.out.println("The nearest perfect square for " + input + " is " + result);

}

public static int findNearestPerfectSquare(int input)

{

//Write code here to find the nearest perfect square for the given input and return the same.

}

}

Topic: for Loop In Java

0

Wrong
Score more than 2 points