Computer Science, asked by samuelshine1120, 1 year ago

Find the execution error int the following program:-
A class finder is created with the following members:-
Variables of the class: Start, Last (integer variables)
Member functions of the class:
i. finder(int s, int L)- a parameterized constructor to assign data Start=s and Last=L
ii. int checkPrime(int d)- to find and return 1 if d is a prime number, else return -1.
iii. void printPrime()- to print only prime numbers between Start to Last limits (both inclusive) by invoking checkPrime().
Write a main() function to input Start and Last limits and print prim numbers by calling suitable functions.

Program:-
import java.io.*;
import java.util.*;
class finder
{
static Scanner sc=new Scanner(System.in);
static int Start, Last;
finder(int s, int L)
{
Start=s;
Last=L;
}
int checkPrime(int d)
{
int count=0;
for(int j=1; j {
if (d%j==0)
{
count++;
}
else
{
count--;
}
}
if(count==2)
{
return 1;
}
else
{
return -1;
}
}
void printPrime()
{
while(Start {
int check=checkPrime(Start);
if (check==1)
{
System.out.print(Start+"\t");
}
else if(check==-1)
{
System.out.print(" ");
}
Start++;
}
}
public static void main(String args[])
{
int s, L;
System.out.println("Enter two numbers");
s=sc.nextInt();
L=sc.nextInt();
finder ob=new finder(s, L);
System.out.println("The prime numbers between "+Start+" and "+Last+" are ");
ob.printPrime();
}
}

Answers

Answered by Anonymous
2


I got following error in compilation:


Compilation Errors Detected

Line: 15

';' expected

Line: 15

illegal start of expression

Line: 15

')' expected

Line: 16

not a statement

Line: 16

';' expected

Line: 20

'else' without 'if'

Line: 25

illegal start of type

Line: 25

<identifier> expected

Line: 25

';' expected

Line: 25

illegal start of type

Line: 25

<identifier> expected

Line: 26

';' expected

Line: 27

illegal start of type

Line: 27

<identifier> expected

Line: 27

';' expected

Line: 29

illegal start of type

Line: 29

<identifier> expected

Line: 30

';' expected

Line: 31

illegal start of type

Line: 31

<identifier> expected

Line: 33

class, interface, or enum expected

Line: 38

class, interface, or enum expected

Line: 41

class, interface, or enum expected

Line: 45

class, interface, or enum expected

Line: 47

class, interface, or enum expected

Line: 49

class, interface, or enum expected

Line: 52

class, interface, or enum expected

Line: 53

class, interface, or enum expected

Line: 54

class, interface, or enum expected

Line: 55

class, interface, or enum expected

Line: 56

class, interface, or enum expected

Line: 57

class, interface, or enum expected

Line: 58

class, interface, or enum expected

Answered by shrabanigupta2010
5

class finder

{

static int Start, Last;

finder(int s, int L)

{

Start=s;

Last=L;

}

int checkPrime(int d)

{

int count=0;

for(int j=1; j <=d;j++){

if (d%j==0)

{

count++;

}

else

{

count--;

}

}

if(count==2)

{

return 1;

}

else

{

return -1;

}

}

void printPrime()

{

int check=checkPrime(Start);

if (check==1)

{

System.out.print(Start+"\t");

}

else if(check==-1)

{

System.out.print(" ");

}

Start++;

}

}

public static void main(String args[])

{

int s, L;

System.out.println("Enter two numbers");

s=sc.nextInt();

L=sc.nextInt();

finder ob=new finder(s, L);

System.out.println("The prime numbers between "+Start+" and "+Last+" are ");

ob.printPrime();

}

}

Similar questions