answersLogoWhite

0


Best Answer

import java.io.*;

class PrimeNumber

{

public static void main(String[] args) throws Exception

{

int i;

BufferedReader bf = new BufferedReader(

new InputStreamReader(System.in));

System.out.println("Enter number:");

int num = Integer.parseInt(bf.readLine());

System.out.println("Prime number: ");

for (i=1; i < num; i++ ){

int j;

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

int n = i%j;

if (n==0){

break;

}

}

if(i == j){

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

}

}

}

}

output:

Enter number:

50

Prime number:

2 3 5 7 11 13 17 19 23 29 31 37 41 43 47BUILD SUCCESSFUL (total time: 3 seconds)

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Java program that prompts the user for an integer and then prints out all prime numbers upto that number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program that prompts the user to input a positive integer It should then output a message indicating whether the number is aprime or not?

Output a prompt.Either:Read from standard input (std::cin) to an integer.Or:Read a line from standard input (std::getline()) to a string.Create a string stream (std::stringstream) to read the string.Read from the string stream to an integer.For each integer from 2 to half the entered integer:If the entered integer is divisible by the current integer:The number is not prime.Exit the program.The number is prime.Exit the program.


Is 2.5 an integer?

No, but 2 and 3 are.No because integers are whole numbers


What is the formula that would get the tenths digit number in a three digit integer number?

In a three digit integer number the tenthsdigit is always 0 as integer numbers are whole numbers and have no decimal part and tenths are decimal parts:tenths_digit_of_integer_number = 0I suspect you mean "How to find the tens digit of an integer number?"; this is the second from the right, so:tens_digit = (INT(number &divide; 10)) MOD 10For example, in C this would become: tens_digit = (number / 10) % 10;


Write a java program to print the last digit in Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.


How do you write a program to find number of zeros for the given number in c program?

Assuming the number is represented by a decimal integer, initialise a counter to zero, then repeatedly divide the number by 10 and until the number is zero. After each division, examine the remainder. Each time the remainder is zero, increment the counter. If the number is represented by a decimal float, repeatedly multiply by 10 until the value is an integer, then perform the previous algorithm.

Related questions

What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


What real number is both integer and a natural number?

Real numbers consist of all numbers except complex numbers. Every integer is a natural number but every rational number is not a natural number as well as an integer. So, the answer to the question is integer.


Is a decimal number an integer?

A decimal number is not an integer. An integer is a number that is not a fraction, and decimal numbers are decimal fractions.


Is 63.46 an integer?

Integer are whole numbers. As 63.46 is not a whole number, it is not an integer.


What number is a rational number but not an integer?

Rational numbers are numbers that can be written as a fraction. Irrational Numbers cannot be expressed as a fraction. Any number that is a fraction is not an integer, but rational.


Is integer another word for number?

No. An integer is a kind of number - a whole number - but not all numbers are integers. For example, a half is a number but it is not an integer.


Is 0.35 an integer?

No because integers are whole numbers


What is an integer that is not a real number?

There is no integer which is not a real number.


Write a program that prompts the user to input a positive integer It should then output a message indicating whether the number is aprime or not?

Output a prompt.Either:Read from standard input (std::cin) to an integer.Or:Read a line from standard input (std::getline()) to a string.Create a string stream (std::stringstream) to read the string.Read from the string stream to an integer.For each integer from 2 to half the entered integer:If the entered integer is divisible by the current integer:The number is not prime.Exit the program.The number is prime.Exit the program.


Why is an integer always a whole number?

An integer is not always a whole number because whole numbers are numbers 0 and up. Integers are numbers above and below 0. (Including negatives.) So therefore, if an integer is a negative, it would not be a whole number. But a whole number is always an integer.


Is 8 an integer in rational numbers?

yes because its an integer and its a number


Is every whole number an integer?

Yes.Yes. The definition of integer is basically 'a whole number.'