Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: composite and prime

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile composite and prime

    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;
    }
    	    }
    ..please help me in this code..there is no prime..
    Last edited by helloworld922; October 13th, 2010 at 04:56 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default 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.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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..

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

Similar Threads

  1. Need help.. Counting Prime #'s up to 50 w/while loop
    By stommy989 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 6th, 2010, 05:40 PM
  2. Generate prime numbers within fiboncacci series?
    By Manish87 in forum Algorithms & Recursion
    Replies: 5
    Last Post: August 7th, 2010, 12:24 PM
  3. Need Help - Factoring & Prime Finding Code
    By prodigytoast in forum Algorithms & Recursion
    Replies: 5
    Last Post: November 5th, 2009, 07:38 AM

Tags for this Thread