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) {
List<String> inputNums= new ArrayList<>();
List<Integer> intList=new ArrayList<>();
List<Integer> primeNums=new ArrayList<>();
Scanner scanner = new Scanner(;
String input = scanner.nextLine();
//numbers from input as str
Pattern nums = Pattern
Matcher matcher = nums.matcher(input);
while (matcher.find()) {
//str to int intList contains all nums
for(String inputNum : inputNums) intList.add(Integer.valueOf(inputNum));
for (int temp = intList.size(),i=0; i < temp; i++) {
int n=intList.get(i);
//check for prime numbers
for (int temp = primeNums.size(), i = 0; i < temp; i++) {
int inputNum = primeNums.get(i);
//primeHash - no duplicates
Set<Integer> primeHash = new HashSet<Integer>(primeNums);
//primeHash>=3 means more or equal to 3 prime numbers
int lenHash=primeHash.size();
Object[] primeObject=primeHash.toArray();
int lenObj=primeObject.length;
int arr[]=new int[lenHash];
for (int i = 0; i < lenObj; i++) {
arr[i]=(int) primeObject[i];
int num1=arr[lenObj-1];
int num2=arr[lenObj-2];
int num3=arr[lenObj-3];
int sum=num1+num2+num3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment