please solve Q8 in bluej.
Attachments:
Answers
Answered by
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");
}
}
}
}
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
Similar questions
English,
7 months ago
Science,
7 months ago
Math,
1 year ago
Chemistry,
1 year ago
Social Sciences,
1 year ago