Skip to content

Instantly share code, notes, and snippets.

@isicju
Created July 9, 2023 14:59
Show Gist options
  • Save isicju/54060ff9468f865211f78beaa777abb4 to your computer and use it in GitHub Desktop.
Save isicju/54060ff9468f865211f78beaa777abb4 to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) throws InterruptedException {
System.out.println("Works");
}
}
@Gavrilova
Copy link

hi

@LeonidKarlovskiy
Copy link

package org.example.problem1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
public static void main(String[] args) {
List inputNumbers = new ArrayList<>();
inputNumbers.addAll(Arrays.asList(3, 1, 31, 31, 31, 31, 9, 0, 4, 5, 7, 33, 4));
System.out.println("Arrays has two items that makes sum of 4: " + hasSum(4, inputNumbers));
}

public static boolean hasSum(int sum, List<Integer> input) {
    for (int i = 0; i < input.size() - 1; i++) {
        int firstNumber = input.get(i);
        for (int j = i + 1; j < input.size(); j++) {
            int secondNumber = input.get(j);
            if (firstNumber + secondNumber == sum) {
                return true;
            }
        }
    }
    return false;

}

}

@LeonidKarlovskiy
Copy link

public static Map<String, User> findLowIncomeCitizens(ArrayList users) {
return users.stream()
.filter(user -> user.getCity().equals("New York") && user.getSalary() < 100L)
.collect(Collectors.toMap(User::getGuid, Function.identity()));
}

public static Country findCountryByName(DataSource dataSource, String countryName) throws SQLException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement("SELECT * FROM countries WHERE name = ?")) {
statement.setString(1, countryName);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
return new Country(countryName, resultSet.getString("region"));
}
}
} catch (SQLException e) {
return null;
}
return null;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment