answersLogoWhite

0


Best Answer

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

13y ago
This answer is:
User Avatar

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.

Related questions

Java code to print prime numbers from 1 to 10?

System.out.println("2, 3, 5, 7"); There are so few you dont need to calculate it


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.


How do you do this java code?

You have to specify the task that you wish me to help you with the Java code.


What does the Java compiler translate Java source code to?

The Java compiler translates Java source code to Java byte code.


How can you print page numbers twice in a row in word?

Page numbers are set in the footer in the page setup. Simply put the code in twice.


What is a simple java code and explain what the code does?

int a;This simple Java statement declares an integer.


In the first step of the Java hybrid compilation process Java program code is converted into an intermediate format called .?

Java byte code.


What kind of file contain java source code?

'.java' files contain java source code. One can access these files on windows by using 'notepad'.


Difference between a java complier and the Java JIT?

A java compiler takes Java source code and turns it into Java bytecode, which can then be run by the java virtual machine.Using JIT means that the java code will be compiled and executed at the time that you run the program, which will slow down the program because it has to compile the code at the same time that it runs.


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