Results 1 to 2 of 2
  1. #1
    Viswanth is offline Member
    Join Date
    Nov 2016
    Posts
    1
    Rep Power
    0

    Default prime no. or not program

    can anyone help me to find out why this code is not working
    Java Code:
    import java.util.Scanner;
    public class prime {
    	public static void main (String args[]){
    		Scanner visu = new Scanner(System.in);
    		int input = visu.nextInt();
    		vis:
    		for (int a =2;;a++){
    			
    			for(int b=2;a*b>input;b++){
    			int output =	a*b;
    				if(input==output){
    					System.out.println(input+" is not a prime number");
    					break vis;
    				}
    				else if(input<=a){
    					System.out.println(input +" is  a prime number");
    					break vis;
    				}
    				
    			}
    			
    		}
    		
    	}}
    Last edited by JosAH; 11-13-2016 at 12:29 PM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: prime no. or not program

    Say 'input' == 9; your inner loop won't run because a and b are both 2 and 2*2 isn't larger than 9 ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. Am I wrong in my prime no. program ?
    By jasnoor.java in forum New To Java
    Replies: 3
    Last Post: 05-02-2016, 06:20 PM
  2. Replies: 6
    Last Post: 12-15-2013, 07:40 AM
  3. Java program prime or not a prime number
    By xswtnsour13x in forum New To Java
    Replies: 2
    Last Post: 10-01-2013, 10:21 AM
  4. Palindrome Prime program
    By Zora in forum New To Java
    Replies: 7
    Last Post: 10-19-2011, 09:42 PM
  5. prime numbers program
    By i contra i in forum New To Java
    Replies: 9
    Last Post: 01-15-2009, 08:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •