# composite and prime

• October 13th, 2010, 02:46 AM
cutee_eyeh
composite and prime
Code Java:

```import java.util.Scanner;   public class erelle{ private static String comps; public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("Please insert a number:"); int number = input.nextInt(); comps = ""; boolean prime = isPrime(number); if(prime){ System.out.println("The number "+number+" is Prime"); } else{ System.out.println("The number "+number+" is composed of "+comps); } } public static boolean isPrime(int num){ boolean isTrue = true; for(int i=1; i<=Math.ceil((num/1)); i++){ if(num%i == 0){ if(comps.equals("")){ comps += ""+i; } else{ comps += ","+i; } isTrue = false; } } return isTrue; } }```
• October 13th, 2010, 07:04 AM
aussiemcgr
Re: composite and prime
Can you wrap your code in JAVA tags so we can read it easier? Look at my signature and try to give us those 3 things so we can help you better.

I would assume you are attempting to create a program that does Prime Numbers. There are several recent posts regarding making a program that finds prime numbers.

This is one of them: http://www.javaprogrammingforums.com...hile-loop.html

Do a quick search (Java Programming Forums - Search Results) and just skim the posts looking for information. If there is still an issue that has not been solved somewhere else or if something confuses you, we can work from there.
• October 13th, 2010, 08:17 PM
cutee_eyeh
Re: composite and prime
..this is a correct code but then the numbers that should be in prime the output would be in composite for example we input 1 the output would be the 1 is composed of 1..thank you..
• October 13th, 2010, 09:01 PM
helloworld922
Re: composite and prime
1 is not prime.

A number is considered prime if it's positive and divisible by any number greater than 1 and less than itself.