Results 1 to 5 of 5
- 04-06-2012, 02:11 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 12
- Rep Power
- 0
Can't compile simple program to calculate primenumber
Can't compile simple program to calculate prime number
The errors that I receive when I try to compile it:Java Code:Class primo { public static void main(String[] args) { int cont=2; for (int i=3; i<1001; i++) { boolean primo = true; for (int j=2; j<i; j++) { if ((i%j) == 0) { boolean = false; break; } } if (boolean == true) System.out.println ("E primo: "+i); cont++; } System.out.println ("numero de primos: "+cont); } }
primo.java:1: class, interface, or enum expected
Class primo {
^
primo.java:2: class, interface, or enum expected
public static void main(String[] args) {
^
primo.java:4: class, interface, or enum expected
for (int i=3; i<1001; i++) {
^
primo.java:4: class, interface, or enum expected
for (int i=3; i<1001; i++) {
^
primo.java:4: class, interface, or enum expected
for (int i=3; i<1001; i++) {
^
primo.java:6: class, interface, or enum expected
for (int j=2; j<i; j++) {
^
primo.java:6: class, interface, or enum expected
for (int j=2; j<i; j++) {
^
primo.java:6: class, interface, or enum expected
for (int j=2; j<i; j++) {
^
primo.java:9: class, interface, or enum expected
break;
^
primo.java:10: class, interface, or enum expected
}
^
primo.java:14: class, interface, or enum expected
cont++;
^
primo.java:15: class, interface, or enum expected
}
^
primo.java:17: class, interface, or enum expected
}
^
13 errors
I checked the number of opened and closed {} and it's the same, five, so I don't know what is going on.
Thanks for the support
- 04-06-2012, 02:26 AM #2
Senior Member
- Join Date
- Feb 2012
- Posts
- 219
- Rep Power
- 2
Re: Can't compile simple program to calculate primenumber
You need to add public before Class and change Class to class. Have you read the basics about Java?
- 04-06-2012, 03:18 AM #3
Member
- Join Date
- Dec 2009
- Posts
- 12
- Rep Power
- 0
- 04-06-2012, 03:24 AM #4
Senior Member
- Join Date
- Feb 2012
- Posts
- 219
- Rep Power
- 2
Re: Can't compile simple program to calculate primenumber
ok, just checking. We all make mistakes. If you make those changes, it still won't compile btw. If you are using an IDE it should help you out.
- 04-06-2012, 04:07 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 12
- Rep Power
- 0
Re: Can't compile simple program to calculate primenumber
Similar Threads
-
Program in Java To calculate GCD of n numbers.?
By ankitsinghal_89 in forum New To JavaReplies: 4Last Post: 02-15-2011, 09:23 AM -
How to write a program to calculate and display sum in two dimensional array?
By Javanoobs in forum New To JavaReplies: 12Last Post: 02-08-2011, 02:58 PM -
How to write a program to calculate and display sum in two dimensional array
By Javanoobs in forum Advanced JavaReplies: 1Last Post: 02-08-2011, 09:11 AM -
First Java Program-Compile Errors (errors are posted)-simple GUI
By cc11rocks in forum AWT / SwingReplies: 4Last Post: 01-04-2011, 12:36 AM -
Why my program cannot calculate the decimal value?
By pearllymary78 in forum New To JavaReplies: 4Last Post: 06-23-2008, 12:52 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks