Java
Programming and Technical
Programming
Database
Find the nearest perfect square of the given number.
Sample input:600
Sample output:576.
Sample input:47011
Sample output:47089
Read Solution (Total 1)
-
- import java.util.Scanner;
public class SqrtP {
public static void main(String[] args) {
int i;
Scanner scan=new Scanner(System.in);
i=scan.nextInt();
int s=(int)Math.sqrt(i);
int floor_int=s;
int ceil_int=floor_int+1;
int floor_int_square=floor_int*floor_int;
int ceil_int_square=ceil_int*ceil_int;
int d1=i-floor_int_square;
int d2=ceil_int_square-i;
if(d1>d2)
{
System.out.println(ceil_int_square);
}
else
System.out.println(floor_int_square);
}
} - 5 years agoHelpfull: Yes(2) No(0)
Java Other Question
Which checks the object code to determine whether there are more efficient means of execution?
1)Interpreter
2) Linker
3)Compiler
4) Optimizer
21. you have three dice each side is numbered as 1,2,3,4,5,6 .you have to take a
number from user check that number as sum of any side number of these
three dice.like we take number as 5 then the possibility are (1,1,3) (1,2,2)
(1,3,1) (2,1,2) (2,2,1) (3,1,1) and is 6 possibility. So write to a program for that.