answersLogoWhite

0


Best Answer

I could write the program quickly, but I want to leave you part of the fun.

Just write a loop for the numbers from 2-100 (1 is not considered a Prime number). Write a second loop to test divisibility of each number, "n", with all factors lower than that number (from 2 to n-1). If such a factor exists, the number is NOT a prime number.

To test for divisibility, use the remainder of a division.

if (n % factor == 0)
// If true, it is divisible.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

import java.io.*;

class Fun

{

public void even(int m,int n) //prints even numbers

{

for(int i=(m+1);i<n;i++)

{

if(i%2==0)

System.out.println(i);

System.out.println("\n");

}

}

public void prime(int x,int y ) //prints prime numbers

{

for(int j=(x+1);j<y;j++)

{

int f=0;

for(int k=2;k<j/2;k++)

{

if(j%k==0)

{

f=1;

break;

}

}

if(f==0)

{ System.out.println(j);

System.out.println("\n");

}

class exe

{

public static void main (String[] args)

{

Fun h=new Fun();

h.even(100,200);

h.prime(100,200);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

public class PerfectNumber{


public static void main(String[]args){

int sum=0, x=0;

for(int num=1;num<500;num++){

for(int i=1;i

x=num%i;

if(x==0)

sum=sum+i;

}

if(sum==num){

System.out.println("Perfect Number is: "+num);

System.out.println("Factors are: ");

for(int i=1;i

x=num%i;

if(x==0)

System.out.println(i);

}

}

sum=0;

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

package javaapplication1;

public class JavaApplication1 {

public static boolean is_prime(int val){

if (val<0) val*=-1;

if (val<2) return false;

if (val%2==0) return val==2;

int max = (int)Math.sqrt(val)+1;

for (int div=3; div<max; ++div)

if (val%div==0)

return false;

return true;

}

public static void main(String[] args) {

System.out.print ("List of primes from 0 to 100:\n");

for (int i=0; i<=100; ++i){

if (is_prime(i)) {

System.out.print (i);

System.out.print (" is prime\n");

}

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

package javaapplication1;

public class JavaApplication1 {

public static boolean is_prime(int val){

if (val<0) val*=-1; // make val positive

if (val<2) return false;

if (val%2==0) return val==2;

int max = (int)Math.sqrt(val)+1;

for (int div=3; div<max; ++div)

if (val%div==0)

return false;

return true;

}

public static void main(String[] args) {

System.out.print ("List of primes from 0 to 100:\n");

for (int i=0; i<=100; ++i){

if (is_prime(i)) {

System.out.print (i);

System.out.print (" is prime\n");

}

}

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to print even and prime numbers from 100 to 200 in core java language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a c program to generate all prime numbers in the given range?

look man that would take alot &gt;&gt;&gt; Ill give you the way =============================================================================== this answer i write it now on net ! i read about that befor in it uni where i study i will chick out the answer and re write it best wishes 2024


What BASIC program can compute and display all prime numbers from 1 to 40?

PRINT 2,3,5,7,11,13,17,19,23,29,31,37


Write a c program to find out the prime numbers between 1 to 500?

Here is a simple program to generate prime numbers upto a given specific number /*Prime No. from 1 to 50*/ /*By-Himanshu Rathee*/ #include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int i,j,n; clrscr(); printf(" Enter the number upto which we have to find the prime number: "); scanf("%d",&amp;n); printf("\n"); for(i=2;i&lt;=n;i++) { for(j=2;j&lt;=i-1;j++) if(i%j==0) break; /*Number is divisble by some other number. So break out*/ if(i==j) printf("\t%d",i); /*Number was divisible by itself (that is, i was same as j)*/ } /*Continue loop upto nth number*/ getch(); }


How do you write a program in lisp to find if a number is prime or not?

(defun prime (num) (if (&lt; 2 num) (do ((dividend 2 (1 + dividend)) (chk-to (sqrt num))) ((equal (rem num dividend) 0)) (when (&lt;= chk-to dividend) (return t))) t))


How do you print non-prime numbers in java?

Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.

Related questions

How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


Program for print prime all number from 1 to 100 in foxpro?

Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.


Write a C program to find the sum of all prime numbers?

Since there is an infinite set of prime numbers the answer would be infinity.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


How can I write a program to display prime numbers from 1 to 100?

Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.


Write a program to print first 100 alternative prime numbers?

This would require some computer knowledge. It can make it easier to find out the prime numbers without figuring it out in your head.


How do you write a c program to get a range from user and give a list of prime numbers?

To get all tutorials of "c programming" Reference:cprogramming-bd.com/c_page2.aspx# prime number


When you write a number as a product of prime numbers?

A number as a product of prime numbers would be &quot;x&quot;.


What to write when describing the properties of prime numbers?

Numbers divisible by 1 &amp; number itself are called prime numbers. These numbers also have the property to be odd numbers.


What numbers as a sum of two prime numbers 95?

You can't write that as the sum of two prime numbers. Note: Goldbach's Conjecture (for expressing numbers as the sum of two prime numbers) applies to EVEN numbers.


How do you write 27 as the product of prime numbers?

Prime factorization of 27 = 3x3x3