Skip to content

Instantly share code, notes, and snippets.

@AndresRodz
AndresRodz / StudentsGrades.java
Created February 17, 2014 01:51
Andres Rodriguez A01193126, Hector Carpizo A01193092
// Andres Rodriguez A01193126, Hector Carpizo A01193092
import java.util.Scanner;
public class StudentsGrades {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
String[] arraynames = Names();
int[] arraygrades = Grades(arraynames);
@AndresRodz
AndresRodz / MaxValue.java
Created February 13, 2014 00:53
Write a method public static int max(int[][] a)that returns the maximum value in the 2d parameter array a.
import java.util.Scanner;
public class MaxValue {
public static void main(String []args) {
Scanner input = new Scanner(System.in);
int positions = input.nextInt();
int[][] a = new int[positions][positions];
@AndresRodz
AndresRodz / InitializedNArray.java
Created February 13, 2014 00:52
Write a method public static int[][] initialize(int n)that returns an initialized array N x N received as parameter with the values starting from 0 to ((N x N) – 1). You should start filling by row.
import java.util.Scanner;
public class InitializedNArray {
public static void main(String []args) {
Scanner input = new Scanner(System.in);
int positions = input.nextInt();
}
@AndresRodz
AndresRodz / Array2or4.java
Created February 13, 2014 00:52
Given an array of ints, return true if the array contains a 2 next to a 2 or a 4 next to a 4, but not both. either24({1, 2, 2}) → true either24({4, 4, 1}) → true either24({4, 4, 1, 2, 2}) → false public boolean either24(int[] nums)
import java.util.Scanner;
public class Array2or4 {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int positions = input.nextInt();
int[] myarray = new int[positions];
@AndresRodz
AndresRodz / TripleNumArray.java
Created February 13, 2014 00:51
Return true if the array contains, somewhere, three increasing adjacent numbers like 4, 5, 6 or 23, 24, 25. tripleUp({1, 4, 5, 6, 2}) → true tripleUp({1, 2, 3}) → true tripleUp({1, 2, 4}) → false public boolean tripleUp(int[] nums)
import java.util.Scanner;
public class TripleNumArray {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int positions = input.nextInt();
int[] myarray = new int[positions];
@AndresRodz
AndresRodz / SumArray13.java
Created February 13, 2014 00:49
Return the sum of the numbers in the array, returning 0 for an empty array. Except the number 13 is very unlucky, so it does not count and numbers that come immediately after a 13 also do not count. sum13({1, 2, 2, 1}) → 6 sum13({1, 1}) → 2 sum13({1, 2, 2, 1, 13}) → 6 public int sum13(int[] nums)
import java.util.Scanner;
public class SumArray13 {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int positions = input.nextInt();
int[] myarray = new int[positions];
@AndresRodz
AndresRodz / ShiftLeftArray.java
Created February 13, 2014 00:48
Return an array that is "left shifted" by one -- so {6, 2, 5, 3} returns {2, 5, 3, 6}. You may modify and return the given array, or return a new array. shiftLeft({6, 2, 5, 3}) → {2, 5, 3, 6} shiftLeft({1, 2}) → {2, 1} shiftLeft({1}) → {1} public int[] shiftLeft(int[] nums)
import java.util.Scanner;
public class ShiftLeftArray {
public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int positions = input.nextInt();
int[] myarray = new int[positions];
@AndresRodz
AndresRodz / UpToLowCase.java
Created February 13, 2014 00:47
Convert an upper-case letter to a lower case letter and return the lower case letter. (Hint: Check first to be sure that it is not lower case already.)
import java.util.Scanner;
public class UpToLowCase{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String upper = input.nextln();
String lower = ToLowCase(upper);
System.out.println(lower);
@AndresRodz
AndresRodz / AppMonth.java
Created February 13, 2014 00:46
Given a number from 1-12, return the name of the appropriate month.
import java.util.Scanner;
public class AppMonth{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
String month = MonthName(n);
System.out.println(month);
@AndresRodz
AndresRodz / SquareAsterisks.java
Created February 13, 2014 00:45
For any given (small) number, print a square of asterisks with the length of each side equal to the given number.
public static void Asterisks(int n) {
String x = "*";
for(int y = 1; y < n; y++){
x = x + " *";
}
for (int z = 0; z < n; z++){
System.out.println(x);
}
}