Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime Finder
#1
This program will ask you for a number and then it will tell you if your number is prime or not.

[code2=java]import java.util.Scanner;


public class primeFinder {

static Scanner scanner = new Scanner(System.in);


public static void main(String[] args)
{
System.out.println("What number would you like to find if it is prime or not:");

int userNum = scanner.nextInt();
int i;

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

int g = userNum % i;

if (g == 0)
{
System.out.println("Your number is not prime!");
break;
}
}
if(i == userNum)
{
System.out.println("Your number is prime!");
}
}
}[/code2]


Messages In This Thread
Prime Finder - by WitherSlayer - 03-09-2013, 07:36 PM
Re: Prime Finder - by brandonio21_phpbb3_import2 - 03-10-2013, 10:34 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)