PrimeNumbers.java

code_warrior 0 Tallied Votes 256 Views Share

This code enables the user to enter a number and finds the prime from 2 to the entered number..Please name it PrimeNumbers.java Hope it'll help u..:D

/*
creator: jennyvi San sebastian




*/


import java.util.Scanner;


public class PrimeNumbers{
	public static void main(String ivy[]){
		
		int input = 0;
		int counter;
		int div;
		String choice = null;
	 
	 do{
			Scanner keyIn = new Scanner(System.in);		
			System.out.print("Enter a number: ");
			input = keyIn.nextInt();
			
			int start = 2;
			
			while (start <= input){
				div = 2;counter = 0;
			
				while (div <= start)
				{
					if (start % div == 0 && div==start)
						{
						counter++;
						}
					if (start % div == 0 && div!=start)
						{
							counter++;
						
						}
										
					div++;
				}
				
				if (counter == 1)
					{
					System.out.print(start + " ");
					}
					
				    start++;
			}
			
			System.out.println();
			
    System.out.println("\nDo you want to continue <YES/N0>: ");
    choice = keyIn.next();
    choice = choice.toUpperCase();
   
  }while(choice.equals("YES"));
		
}
atong 0 Newbie Poster

can you create a code radix for ex: 1*10^6 + 2*10^5 + 3*10^4 +
4*10^3 + 5*10^2 + 6*10^1
coz i can't just get its iteration and slpiting the #s

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.