A very simple program to list down the prime numbers from 1 to 220 using Java as our programming language.
I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My mobile number here in the Philippines is 09173084360.
I am currently accepting programming and web development work kindly contact me in the following email address for further details. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Sample Program Output
Program Listing
public class Main {
public static void main(String[] args) {
int a =0;
int num =0;
System.out.println("\n\n");
System.out.print("List of Prime Number in Java");
System.out.println("\n");
String primeNumbers = "";
for (a = 1; a <= 220; a++)
{
int counter=0;
for(num =a; num>=1; num--)
{
if(a%num==0)
{
counter+=1;
}
}
if (counter ==2)
{
primeNumbers += a + " ";
}
}
System.out.println("Prime numbers from 1 to 220 are :");
System.out.println(primeNumbers);
System.out.println();
System.out.print("End of Program");
System.out.println();
}
}
public static void main(String[] args) {
int a =0;
int num =0;
System.out.println("\n\n");
System.out.print("List of Prime Number in Java");
System.out.println("\n");
String primeNumbers = "";
for (a = 1; a <= 220; a++)
{
int counter=0;
for(num =a; num>=1; num--)
{
if(a%num==0)
{
counter+=1;
}
}
if (counter ==2)
{
primeNumbers += a + " ";
}
}
System.out.println("Prime numbers from 1 to 220 are :");
System.out.println(primeNumbers);
System.out.println();
System.out.print("End of Program");
System.out.println();
}
}
No comments:
Post a Comment