Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Something is wrong? Please help.

What did I do wrong with this code? I thought it compiled great.

```import java.util.Scanner;

public class mycode_Sieve
{
private boolean primes[] = new boolean ;

private int upper = 50000;

private int lower = 1;

public void processSieve()
{
primes = false;
primes = false;
for (int a = 2; a < 50000; a++)
{
primes[a] = true;
}

for (int a = 2; a <= 223; a++)
{
if (primes[a])
{
for (int b = a; b <= 223; b++)
{
int c = (a * b);
primes[c] = false;
}
}
}
}

public void getBoundaries()
{
System.out.println ("Please enter a lower boundary and an upper boundary and I will print sexy prime pairs between those boundaries.");

Scanner i = new Scanner (System.in);

System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
while ((lower <= 0) || (lower > 50000))
{
System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
}

System.out.print("Please enter the upper boundary (between 1 and 50000): ");

upper = i.nextInt();
while ((upper <= 0) || (upper > 50000))
{
System.out.print("Please enter the upper boundary (between 1 and 50000): ");
upper = i.nextInt();
}

while (lower > upper)
{

System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
while ((lower <= 0) || (lower > 50000))
System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
}

System.out.print("Please enter the upper boundary (between 1 and 50000): ");
upper = i.nextInt();
while ((upper <= 0) || (upper > 50000))
{
System.out.print("Please enter the upper boundary (between 1 and 50000): ");
upper = i.nextInt();
}

}

}

public void showPrimes()
{
System.out.printf("Here are all of the sexy prime pairs in the range %d to %d, one pair per line:\n", lower, upper);

int counter = 0;
for (int a = lower; a <= upper; a++)
{
if (primes[a] == true)

{
int b = (a + 6);
if (b <= 50000)
{
if (primes[b] == true)
{
System.out.printf("%d and %d\n", a, b);
counter++;
}
}
}
}

System.out.printf("There were %d sexy prime pairs displayed between %d and %d\n", counter, lower, upper);
}
}```  Reply With Quote

3. ## Re: Something is wrong? Please help.

The problem is you had an extra curly bracket you didn't need. Please see the below code. I have highlighted the error..

```import java.util.Scanner;

public class mycode_Sieve
{
private boolean primes[] = new boolean ;

private int upper = 50000;

private int lower = 1;

public void processSieve()
{
primes = false;
primes = false;
for (int a = 2; a < 50000; a++)
{
primes[a] = true;
}

for (int a = 2; a <= 223; a++)
{
if (primes[a])
{
for (int b = a; b <= 223; b++)
{
int c = (a * b);
primes[c] = false;
}
}
}
}

public void getBoundaries()
{
System.out.println ("Please enter a lower boundary and an upper boundary and I will print sexy prime pairs between those boundaries.");

Scanner i = new Scanner (System.in);

System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
while ((lower <= 0) || (lower > 50000))
{
System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
}

System.out.print("Please enter the upper boundary (between 1 and 50000): ");

upper = i.nextInt();
while ((upper <= 0) || (upper > 50000))
{
System.out.print("Please enter the upper boundary (between 1 and 50000): ");
upper = i.nextInt();
}

while (lower > upper)
{

System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
while ((lower <= 0) || (lower > 50000))
System.out.print("Please enter the lower boundary (between 1 and 50000): ");
lower = i.nextInt();
}

System.out.print("Please enter the upper boundary (between 1 and 50000): ");
upper = i.nextInt();
while ((upper <= 0) || (upper > 50000))
{
System.out.print("Please enter the upper boundary (between 1 and 50000): ");
upper = i.nextInt();
}

}

[B]//error here
//    }
[/B]
public void showPrimes()
{
System.out.printf("Here are all of the sexy prime pairs in the range %d to %d, one pair per line:\n", lower, upper);

int counter = 0;
for (int a = lower; a <= upper; a++)
{
if (primes[a] == true)

{
int b = (a + 6);
if (b <= 50000)
{
if (primes[b] == true)
{
System.out.printf("%d and %d\n", a, b);
counter++;
}
}
}
}

System.out.printf("There were %d sexy prime pairs displayed between %d and %d\n", counter, lower, upper);
}
}```

This should compile fine now   Reply With Quote

4. ## Re: Something is wrong? Please help.

So I dont need a constructor method as per UML spec?  Reply With Quote

5. ## Re: Something is wrong? Please help. Originally Posted by DestinyChick1225 So I dont need a constructor method as per UML spec?
?? All I have done is removed an extra bracket you added by mistake   Reply With Quote