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
| /* | |
| 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++) { |
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 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}; |
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
| /* | |
| 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(); |
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 codingbat; | |
| import java.util.Arrays; | |
| /** | |
| * Created by Влад on 16.11.2016. | |
| */ | |
| public class TestString3countYZ { | |
| public static void main(String[] args) { |
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
| /* | |
| 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(); |
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 codingbat; | |
| /** | |
| * Created by Влад on 16.11.2016. | |
| */ | |
| public class TestString3sumNumbers { | |
| public static void main(String[] args) { | |
| String input1 = "abc123xyz"; |
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 codingbat; | |
| import java.util.Arrays; | |
| /** | |
| * Created by Влад on 16.11.2016. | |
| */ | |
| public class TestString3countYZ { | |
| public static void main(String[] args){ |
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 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 { |