Computer Science, asked by chaitanyapurohpb1gqe, 1 year ago

please solve Q8 in bluej.

Attachments:

Answers

Answered by nitish8089
1
import java.util.Scanner;

public class Program

{

public static void main(String[] args) {

Scanner in=new Scanner(System.in);

int a=in.nextInt();

System.out.print("number enter by you: "+a);

int i=0;

int c=a;

do{

c-=(2*i+1);

i++;

}while(c>0);

if(c==0){

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

}

else{

System.out.println(" not perfect square number");

}

}

}
____________________
without using any loop::
import java.util.Scanner;

public class Program

{
public static void

main(String[] args) {

Scanner sc=new
Scanner(System.in);

int a=sc.nextInt();

if(a<0){
System.out.println("not a perfect square");

}

else{

int temp=(int)(Math.sqrt(a));

int temp1=(int)(Math.pow(temp, 2));

if(temp1==a){
System.out.println("perfect square");

}

else{
System.out.println("not a perfect square");

}

}
}
}

chaitanyapurohpb1gqe: please write without for loop
nitish8089: hey for loop is not here.. i will use algorithm if we use method then only one line answer
chaitanyapurohpb1gqe: sorry let me rephrase
chaitanyapurohpb1gqe: not any type of loop
nitish8089: i will post it but in some time it wouldn't give edit option so ask same question .. second time
nitish8089: answer updated i will not using any loop this time..
Similar questions