answersLogoWhite

0

import java.io.*;

class prmNo

{

public static void main(String[] args)

{

Console con = System.console();

System.out.println("Enter length of list :");

int n = con.readLine();

boolean flag;

System.out.print("1 ");

for (int i=2;i<=n;i++)

{

for (int j=2;j<i;j++)

{

if (i%j==0)

flag=true;

}

if(!flag)

System.out.print(i+ " ");

flag=false;

}

}

}

User Avatar

Wiki User

14y ago

Still curious? Ask our experts.

Chat with our AI personalities

JudyJudy
Simplicity is my specialty.
Chat with Judy
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran

Add your answer:

Earn +20 pts
Q: Java code to print prime numbers from 1 to 100?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Math & Arithmetic

Without array Java code to print prime numbers from 1 to 100?

public class Primes { public static void main(String[] args) { for(int i = 2; i &lt; 100; i++) { if(isPrime(i)) { System.out.println(i); } } } public static boolean isPrime(int n) { if(n 0) return false; } return true; } } }


What is the pseudo code to delete prime numbers from linked-list?

It sounds like you're using Java, so instead of pseudo-code, I'll give you the actual code. LinkedList&lt;Integer&gt; l; // Let's assume you have a bunch of Integer values in this list. for (int i = 0; i &lt; l.size(); i++){ int n = l.get(i); boolean prime = true; for (int i = 2; i &lt; n; i++){ if (n % i == 0){ prime = false; break; } } if (prime){ l.remove(i); i--; } }


Why are prime numbers used in code creations?

I use prime numbers in code to catalog things with one number. I assign a prime number to a certain characteristic. Then I multiply together the prime numbers for each characteristic contained. Later, that number can be divided a prime number. If a remainder of zero is returned I know it contains the number and what too associate it with.


What are a dozen or more facts about prime numbers?

1 Prime numbers have only 2 factors which are themselves and one 2 Prime numbers can't be composite numbers which have more than 2 factors 3 Prime numbers are odd except for two which is the only even prime number 4 Prime numbers are used in finding the LCM of 2 or more numbers 5 Prime numbers are used in finding the HCF of 2 or more numbers 6 Prime numbers are used in finding the LCD of fractions 7 Prime numbers are used in reducing fraction to their lowest terms 8 Prime numbers are rational because they can be expressed as fractions 9 Prime numbers are infinite 10 Prime numbers are irrational when square rooted 11 Prime numbers can't be 0 or 1 which are also not composite numbers 12 Prime numbers don't follow a forecasted numerical pattern 13 Prime numbers make up 25% of the first 100 integers or whole numbers 14 Prime numbers have a code amongst themselves that has never been cracked


Why do prime numbers matter?

Prime numbers are important for several applications, such as cryptography and information technology. They are also useful for some simpler tasks in mathematics (for example, finding the common factors of two numbers). Prime numbers are usefull in encryption because code breaking computers employ search algorithms that keep multiplying numbers together In order to find a combination to break the code, but if you have a very large prome, the code breaker probably won't find it. The Unique-Prime-Factorization Theorem is so useful, that it is also called the Fundamental Theorem of Arithmetic.