Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Exam_Problem3_Biggest3PrimeNumbers {
public static void main(String[] args) {
//inputNumbers contains all numbers from the input
List<String> inputNumbers= new ArrayList<>();
int result=0;
Scanner scanner = new Scanner(;
String input = scanner.nextLine();
//find numbers from the input -> write them in inputNumbers
Pattern nums = Pattern
Matcher matcher = nums.matcher(input);
while (matcher.find()) {
List<Integer> intList=new ArrayList<>();
List<Integer> primeNums=new ArrayList<>();
//str to int -> intList contains all nums as integers, instead of strings
for(String inputNumber : inputNumbers) intList.add(Integer.valueOf(inputNumber));
//check if numbers in intList are prime
for (int len = intList.size(),i=0; i < len; i++) {
int n=intList.get(i);
//check for prime numbers
// 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
//all prime numbers go in primeNums
//for (int len = primeNums.size(), i = 0; i < len; i++) {
//int s = primeNums.get(i);
//primes contains prime numbers w/o duplicates
Set<Integer> primes = new HashSet<Integer>(primeNums);
int len=prime.size();
//array of prime numbers - primeArr object ->arr
Object[] primeArr=prime.toArray();
//length of primeArr
int lenPrimeArr=primeArr.length;
int arr[]=new int[lenPrimeArr];
for (int i = 0; i < lenPrimeArr; i++) {
arr[i]=(int) of[i];
int num1=arr[len1-1];
int num2=arr[len1-2];
int num3=arr[len1-3];
int sum=num1+num2+num3;
//int sum=num1+num2+num3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.