Blogroll

This blog is created for education about engineering students.All the engineering students are get free downloadable books here. not only books and also different software also available here

2.a.Prime numbers


Week 2 :

a)    Write a Java program that prompts the user for an integer and then prints out all prime numbers up to that integer.

import java.lang.*;
import java.io.*;
class prime
{
  public static void main(String args[])
 {
  int n=Integer.parseInt(args[0]);
  for(int r=0;r
  {
   int t=0;
   for(int i=1;i
  {
   if (r%i==0)
  {
   t++;
   }
  }
  if(t<2)
  {
   system.out.print(r);
   system.out.print(" ");
   }
  }
 }
}

No comments:

Post a Comment

Total Pageviews