Computer Science, asked by Kittorani, 1 year ago

Write a program in java to accept a number and check whether the number is a perfect square or not

Answers

Answered by nain31
9

 \huge{ANSWER}

Java is a machine independent language which can work on any platform. Its an object oriented programming which stress on object rather than data.

The main parts while doing Java programming are package, Class ,input variables, condition updating.

◼A perfect number is the number which Is square of other number .

Ex. 4=2×2

9=3×3

The following programming is done by io package of Java.

import Java. io. *;

class check

{

public static void main(String args[])throws Exception

{

DataInputStream in = new DataInputStream(System.in);

int n, s=0;

System. out. println("Enter any number ");

n=Interger.parseInt(in.readLine());

s=Math.sqrt(n)

if((s*s)==n)

System. out. println("The number is perfect square ");

else

System. out. println("The number isn't perfect square ");

}

}

Answered by atrs7391
1

package com.company;

/* Write a program to accept a number and check whether the number is a perfect square or not.

Sample Input=49

Sample Output= A perfect square.

*/

import java.util.Scanner;

public class Main

{

   public static void main(String[] args)

   {

       Scanner sc = new Scanner (System.in);

       System.out.println("Enter a Number:");

       double n = sc.nextDouble();

       double n2 = Math.sqrt(n);

       if (n2%1==0) {

           System.out.println("The entered number is a perfect square");

       }

       else {

           System.out.println("The entered number is not a perfect square");

       }

   }

}

Similar questions