Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Prime Numbers
- * @author Maximilian Krause
- * @since 11-06-2015
- * @ver 1.1.1
- *
- * This script is capable of finding the prime numbers between two specific numbers.
- *
- * Changelog
- * ---------
- * v1.1
- * @since 11-06-2015
- * - Added feature to remove the last comma through a substring.
- *
- * v1.1.1
- * @since 11-06-2015
- * - Fixed too early printing of the number 2.
- *
- * Licensed under CC BY 4.0.
- *
- * TODO: Add multi-threading
- */
- package de.maxkrause;
- import java.util.*;
- public class main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- System.out.print("Which number should be checked first? ");
- int firstCheck = scan.nextInt();
- System.out.print("Which number should be checked last? ");
- int lastCheck = scan.nextInt();
- scan.close();
- System.out.println("Job starting. Please wait...");
- String output = "";
- if(firstCheck < 3){
- firstCheck = 3;
- }
- for(int i = firstCheck; i <= lastCheck; i++){
- boolean isPrime = true;
- for(int j = i-1; j > 0; j--){
- if(j != 0 && j != 1){
- if(i % j == 0){
- isPrime = false;
- }
- }
- }
- if(isPrime){
- output += i + ", ";
- }
- }
- if(!(firstCheck > 2)){
- System.out.print("2, ");
- }
- System.out.println(output.substring(0, output.length()-2));
- System.out.println("Job completed.");
- }
- }
Add Comment
Please, Sign In to add comment