-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
93 lines (79 loc) · 2.88 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import com.sun.source.tree.Tree;
import java.util.*;
public class Main {
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int[] zakres;
System.out.println("Poczatek zakresu: ");
int x = scanner.nextInt();
System.out.println("Koniec zakresu: ");
int y = scanner.nextInt();
int size = y-x+1;
List<Integer> list = new ArrayList<Integer>();
while(y<x)
{
System.out.println("koniec zakresu musi byc wiekszy niz poczatek sprobuj ponownie.");
System.out.println("Poczatek zakresu: ");
x = scanner.nextInt();
System.out.println("Koniec zakresu: ");
y = scanner.nextInt();
}
TreeMap<Integer,ArrayList<int[]>> integerMap = new TreeMap<>();
for (int i = x; i <= y; i++)
{
for (int j = i; j <= y; j++)
{
int tmp = i*j;
int[] products = {i, j};
if(!integerMap.keySet().contains(tmp))
{
ArrayList<int[]> productsList = new ArrayList<int[]>();
productsList.add(products);
integerMap.put(tmp,productsList);
}
else if(integerMap.keySet().contains(tmp))
integerMap.get(tmp).add(products);
}
}
String test = "blacipabla";
int subIndex = test.indexOf('c');
String sub = test.substring(0,subIndex);
System.out.println(sub);
ifPalindrom(integerMap);
result(integerMap);
}
public static List<Integer> stringList= new ArrayList<Integer>();
public static void result(TreeMap<Integer,ArrayList<int[]>> map) {
int smallest = map.firstKey();
ArrayList<int[]> smallestValue = map.get(smallest);
int biggest = map.lastKey();
ArrayList<int[]> biggestValue = map.get(biggest);
System.out.println(smallest + " and its products: ");
for (int[] printable : smallestValue) {
System.out.println(Arrays.toString(printable));
}
System.out.println(biggest + " and its products: ");
for (int[] printable : biggestValue) {
System.out.println(Arrays.toString(printable));
}
}
public static void ifPalindrom(Map<Integer,ArrayList<int[]>> map)
{
Iterator<Integer> it = map.keySet().iterator();
while(it.hasNext())
{
int liczba = it.next();
String number = String.valueOf(liczba);
for (int i = 0; i < number.length(); i++)
{
if(!(number.charAt(i)==number.charAt(number.length()-1-i)))
{
int key = Integer.parseInt(number);
if(map.containsKey(key))
it.remove();
}
}
}
}
}