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

    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(;
    		int input = visu.nextInt();
    		for (int a =2;;a++){
    			for(int b=2;a*b>input;b++){
    			int output =	a*b;
    					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 11:29 AM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    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,

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

Similar Threads

  1. Am I wrong in my prime no. program ?
    By in forum New To Java
    Replies: 3
    Last Post: 05-02-2016, 05:20 PM
  2. Replies: 6
    Last Post: 12-15-2013, 06: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, 09:21 AM
  4. Palindrome Prime program
    By Zora in forum New To Java
    Replies: 7
    Last Post: 10-19-2011, 08:42 PM
  5. prime numbers program
    By i contra i in forum New To Java
    Replies: 9
    Last Post: 01-15-2009, 07: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