Задачі - http://codegym.in.ua/courses/3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import graph.Edge; | |
import java.util.*; | |
import java.util.PriorityQueue; | |
public class PrimSolution { | |
private List<Set<Edge>> graph = new ArrayList<>(); | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ua.codegym.forum.servlet; | |
import ua.codegym.forum.model.User; | |
import javax.servlet.ServletException; | |
import javax.servlet.http.Cookie; | |
import javax.servlet.http.HttpServlet; | |
import javax.servlet.http.HttpServletRequest; | |
import javax.servlet.http.HttpServletResponse; | |
import java.io.IOException; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SumDigits { | |
public static void main(String[] args) { | |
int actual = new SumDigits().sum(123); | |
System.out.println(actual); | |
} | |
public int sum(int number) { | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.Iterator; | |
public class StringTokenizer implements Iterable<String>, Iterator<String> { | |
private InputStream in; | |
public StringTokenizer(InputStream in) { | |
this.in = in; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FindDistance { | |
public static int find(int[] array) { | |
int distance = (array.length > 1) ? 1 : 0; | |
if (array.length > 1) { | |
int min1 = array[0], min2 = array[1], | |
index1 = 0, index2 = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FindDistance { | |
public static void main(String[] args) { | |
int[] array = {1, 2, 2, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2}; | |
int distance = 0; | |
if (array.length > 1) { | |
int min1 = array[1], min2 = array[0], index1 = 1, index2 = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LonelyNumber { | |
public static void main(String[] args) { | |
int[] arr = {1, 2, 4, 2, 3, 7, 2, 1, 3, 4, 1, 3, 4}; | |
int[] bits = new int[32]; // will acomulate bits here | |
for (int num : arr) { | |
for (int i = 0; i < bits.length; i++) { // go through all bits in a number | |
int oneBitNum = 1 << i; | |
if ((num & oneBitNum) > 0) { // check if bit on i-th position equals 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DigitsSum { | |
public static void main(String[] args) { | |
if (args.length > 0) { | |
int num = Integer.parseInt(args[0]); // 123 | |
int result = 0; | |
while (num > 0) { | |
result += num % 10; | |
num /= 10; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StateMachine { | |
public boolean isNumber(String s) { | |
boolean result = false; | |
if (s!= null && s.length() > 0) { | |
State state = State.INIT; | |
int i = 0; | |
while (!state.isEnd() && i < s.length()) { | |
char c = s.charAt(i++); | |
state = state.next(c); |
NewerOlder