Skip to content

Instantly share code, notes, and snippets.

View shalamai's full-sized avatar

Vladyslav Shalamai shalamai

View GitHub Profile
/*
Given n>=0, create an array length n*n with the following pattern, shown here for n=3 : {0, 0, 1, 0, 2, 1,
3, 2, 1} (spaces added to show the 3 groups).
*/
public static int[] squareUp(int n) {
int[] arr = new int[n * n];
int index = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
package codingbat;
import java.util.Arrays;
/**
* Created by Влад on 17.11.2016.
*/
public class TestArray3squareUp {
public static void main(String[] args) {
int[] input = {3, 2, 4, 1, 0, 6};
/*
Given a string, return the sum of the numbers appearing in the string, ignoring all other characters.
A number is a series of 1 or more digit chars in a row. (Note: Character.isDigit(char) tests if a char is one
of the chars '0', '1', .. '9'. Integer.parseInt(string) converts a string to an int.)
*/
public static int sumNumbers(String str) {
boolean b = false;
int sum = 0;
String s = new String();
package codingbat;
import java.util.Arrays;
/**
* Created by Влад on 16.11.2016.
*/
public class TestString3countYZ {
public static void main(String[] args) {
@shalamai
shalamai / String3.java
Created November 16, 2016 12:59
return sum of the numbers appearing in the string
/*
Given a string, return the sum of the numbers appearing in the string, ignoring all other characters.
A number is a series of 1 or more digit chars in a row. (Note: Character.isDigit(char) tests if a char is one
of the chars '0', '1', .. '9'. Integer.parseInt(string) converts a string to an int.)
*/
public static int sumNumbers(String str) {
boolean b = false;
int sum = 0;
String s = new String();
@shalamai
shalamai / TestString3sumNumbers.java
Created November 16, 2016 12:58
test of method sumNumbers()
package codingbat;
/**
* Created by Влад on 16.11.2016.
*/
public class TestString3sumNumbers {
public static void main(String[] args) {
String input1 = "abc123xyz";
@shalamai
shalamai / TestString3countYZ.java
Created November 16, 2016 09:04
test for method countYZ()
package codingbat;
import java.util.Arrays;
/**
* Created by Влад on 16.11.2016.
*/
public class TestString3countYZ {
public static void main(String[] args){
@shalamai
shalamai / countYZ.java
Created November 16, 2016 05:54
count the number of words ending in 'y' or 'z'
package codingbat;
/**
* Created by Влад on 16.11.2016.
* Given a string, count the number of words ending in 'y' or 'z' -- so the 'y' in "heavy" and the 'z' in "fez" count,
* but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not
* an alphabetic letter immediately following it.
*/
public class countYZ {