I wrote a simple program on blueJ and compiled it successfully but when i tried to run it nothing happened.What could be the possible reason..how to fix it?
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
Members have full access to the forums. Advertisements are removed for registered users.
I wrote a simple program on blueJ and compiled it successfully but when i tried to run it nothing happened.What could be the possible reason..how to fix it?
Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.
Tried to run it or actually ran it? Because the code doesn't do anything? No way to tell without seeing the code. When you post the code, please post your code correctly per the above link.
import java.io.*;
class arm
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n=0,c=0,i=0;
for(i=1;i<=n;i++)
{
c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
System.out.println(n);
}
}
}
As I asked, please post your code correctly.
In Java, class names begin with capital letters.
What's the BufferedReader for?
Your code is hard to read, but I think it will only "do something" visible by printing 'n' if 'c' equals 2. When will that happen? You should trace your code line by line to see what is happening to better understand the results you're seeing or not seeing. Then, you might add some other print statements to show the values of 'n', 'c', 'i', etc. at various points to see if your code tracing was correct.
Others like to start or end their main() method with a simple print statement like "Starting main() method," or "Leaving main() method," so that you have some confidence that the program is doing something.
These are basic debugging techniques that you should learn and employ.
--- Update ---
As I asked, please post your code correctly.
In Java, class names begin with capital letters.
What's the BufferedReader for?
Your code is hard to read, but I think it will only "do something" visible by printing 'n' if 'c' equals 2. When will that happen? You should trace your code line by line to see what is happening to better understand the results you're seeing or not seeing. Then, you might add some other print statements to show the values of 'n', 'c', 'i', etc. at various points to see if your code tracing was correct.
Others like to start or end their main() method with a simple print statement like "Starting main() method," or "Leaving main() method," so that you have some confidence that the program is doing something.
These are basic debugging techniques that you should learn and employ.