Kavinda Chathuranga
java algorithem
2 Answer(s)      5 years and 11 months ago
Posted in : Java Beginners

how do i write a algorithm to find all prime numbers less than 100, can you give me the code example?

Ads

View Answers

November 4, 2010 at 1:10 PM


import java.io.*; class Primeseries { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("enter no.:"); int n=Integer.parseInt(br.readLine()); int i=3,j,k=1,count; System.out.println("prime no. are :"); if(n==1) System.out.println(i); else if(n>=2) { System.out.println(k+"\n"+(k+1));

for(i=3;i<=n;i++)
{count=0;
for(j=1;j<=i;j++)
{
    int d=i%j;
    if(d==0)
    count++;
}
if(count<=2)
System.out.println(i);

}

} }}

give n as 100.



November 4, 2010 at 1:17 PM


import java.io.*; class Primeseries { public static void main(String args[]) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("enter no.:"); int n=Integer.parseInt(br.readLine()); int i=1,j,k=1,count; System.out.println("prime no. are :"); if(n==1) System.out.println(i); else if(n>=2) { System.out.println(k+"\n"+(k+1));

for(i=3;i<=n;i++)
{count=0;
for(j=1;j<=i;j++)
{
    int d=i%j;
    if(d==0)
    count++;
}
if(count<=2)
System.out.println(i);

}

} }}

give n as 100.










Related Tutorials/Questions & Answers:
java algorithem
java algorithem  how do i write a algorithm to find all prime numbers less than 100, can you give me the code example?   import java.io.*; class Primeseries { public static void main(String args[]) throws IOException
java
java  3.write an algorithem and the java program that declars.... for example 197mintes becomes 3 hours ad 17 minutes save the program as time java. Write an algorithem aprogram that reads an integer between0 and 1000 and adds all
Advertisements
y
y  3.write an algorithem and the java program that declars aminutes variable that represents minutes worked on ajob and reads avalue using Dialog Box... 197mintes becomes 3 hours ad 17 minutes save the program as time java
java
java  diff bt core java and java
java
java  what is java
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  is java purely object oriented language
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  sample code for RARP using java
java
java  RARP implementation using java socket
Java
Java  how to draw class diagrams in java
java
java  explain object oriented concept in java

Ads

Advertisement