diff --git a/338/lab2/can.java b/338/lab2/can.java deleted file mode 100644 index 47c88ce..0000000 --- a/338/lab2/can.java +++ /dev/null @@ -1,55 +0,0 @@ -// Alejandro Santillana -/* -* given an array of int values, -* is there a index in the array where the sum of values[0 .. index] -* is equal to (or balances) the sum of values[index+1 .. length-1] -* look at the examples below -* Your task: design and code the canBalance methods that returns true or false -* the program should be efficient. -* can you solve the problem without using nested loops? 1 loop? 2 loops? -* Then run the program to see if your method works correctly. -*/ - -public class CanBalance { - - public static void main(String[] args) { - boolean r; - r = canBalance(new int[] {1, 1, 1, 2, 1}); - System.out.println("canBalance( [1, 1, 1, 2, 1] ) should be true. You returned "+r); - - r = canBalance(new int[] {2, 1, 1, 2, 1 }); - System.out.println("canBalance( [2, 1, 1, 2, 1]) should be false. You returned "+r); - - r = canBalance(new int[] {10, 10}); - System.out.println("canBalance( [10,10]) should be true. You returned "+r); - - r = canBalance(new int[] {10, 0, 1, -1, 10} ); - System.out.println("canBalance([10, 0, 1, -1, 10]) should be true. You returned "+r); - - r = canBalance(new int[] { 1}); - System.out.println(" should be false. You returned "+r); - - r = canBalance(new int[] {2, 1, 1, 1, 1}); - System.out.println("canBalance([2, 1, 1, 1, 1]) should be true. You returned "+r); - - } - - public static boolean canBalance(int[] a) { - int sum_a = 0; - int sub_b = 0; - - for(int i =0;i - - - - POST data - - - - - - - -
- - - - -
- - - diff --git a/338/roman/Roman.java b/338/roman/Roman.java deleted file mode 100644 index d5fe852..0000000 --- a/338/roman/Roman.java +++ /dev/null @@ -1,127 +0,0 @@ -import java.util.Scanner; -/** - * Roman numerals - * I 1 - * V 5 - * X 10 - * L 50 - * C 100 - * D 500 - * M 1000 - * - * Numbers are written in decreasing value - * Example: XII is 12, not IIX or IXI - * - * But there are special rules: - * I can come before V or X IV = 4, IX = 9 - * X can come before L or C XL = 40, XC = 90 - * C can come before D or M CD = 400 CM = 900 - */ -public class Roman { - - public static String intToRoman(int n) { - String ret = ""; - int val = n; - // dealing with the thousands case - if(n > 1000) { - int m = val / 1000; - for(int i =0;i=900) { - ret += "CM"; - val -= 900; - } - // 600-800 range - if(val>=600) { - int c = (val - 500)/100; - for(int i =0;i=500) { - ret += "D"; - val -= 500; - } - // 400 special case - if(val>=400) { - ret +="CD"; - val -= 400; - } - // 100 - 300 range - if(val>=100) { - int x = (val - 100)/100; - for(int i =0;i=90) { - val -=90; - ret += "XC"; - } - if(val>=50) { - ret += "L"; - int L=(val-50)/10; - - for(int i =0;i=40) { - ret += "XL"; - val -= 40; - } - if(val>=10) { - int x = (val - 10)/10; - for(int i =0;i5){ - int c = (val - 5); - for(int i =0;i