From 88e09d3d46f398b61a59933523b551ff2bf73323 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Tue, 20 Oct 2020 22:21:15 +0700 Subject: [PATCH] add Week8 Files --- Week8/EclipseIDE/Assignment8/.classpath | 10 ++ Week8/EclipseIDE/Assignment8/.project | 17 +++ .../.settings/org.eclipse.jdt.core.prefs | 14 +++ .../Assignment8/bin/module-info.class | Bin 0 -> 150 bytes .../Assignment8/bin/partA/IsReverse.class | Bin 0 -> 1789 bytes .../Assignment8/bin/partA/package-info.class | Bin 0 -> 111 bytes .../Assignment8/bin/partB/Replace.class | Bin 0 -> 1927 bytes .../Assignment8/bin/partB/package-info.class | Bin 0 -> 111 bytes .../Assignment8/bin/partC/CountNumbers.class | Bin 0 -> 1631 bytes .../Assignment8/bin/partC/package-info.class | Bin 0 -> 111 bytes .../Assignment8/bin/partD/InsertArray.class | Bin 0 -> 2219 bytes .../Assignment8/bin/partD/package-info.class | Bin 0 -> 111 bytes Week8/EclipseIDE/Assignment8/numbers.txt | 100 ++++++++++++++++++ .../Assignment8/src/module-info.java | 2 + .../Assignment8/src/partA/IsReverse.java | 37 +++++++ .../Assignment8/src/partA/package-info.java | 1 + .../Assignment8/src/partB/Replace.java | 56 ++++++++++ .../Assignment8/src/partB/package-info.java | 1 + .../Assignment8/src/partC/CountNumbers.java | 31 ++++++ .../Assignment8/src/partC/package-info.java | 1 + .../Assignment8/src/partD/InsertArray.java | 60 +++++++++++ .../Assignment8/src/partD/package-info.java | 1 + Week8/SublimeText/CountNumbers.class | Bin 0 -> 1590 bytes Week8/SublimeText/CountNumbers.java | 30 ++++++ Week8/SublimeText/InsertArray.class | Bin 0 -> 1802 bytes Week8/SublimeText/InsertArray.java | 58 ++++++++++ Week8/SublimeText/IsReverse.class | Bin 0 -> 1940 bytes Week8/SublimeText/IsReverse.java | 35 ++++++ Week8/SublimeText/Replace.class | Bin 0 -> 1645 bytes Week8/SublimeText/Replace.java | 55 ++++++++++ Week8/SublimeText/numbers.txt | 100 ++++++++++++++++++ 31 files changed, 609 insertions(+) create mode 100644 Week8/EclipseIDE/Assignment8/.classpath create mode 100644 Week8/EclipseIDE/Assignment8/.project create mode 100644 Week8/EclipseIDE/Assignment8/.settings/org.eclipse.jdt.core.prefs create mode 100644 Week8/EclipseIDE/Assignment8/bin/module-info.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partA/IsReverse.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partA/package-info.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partB/Replace.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partB/package-info.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partC/CountNumbers.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partC/package-info.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partD/InsertArray.class create mode 100644 Week8/EclipseIDE/Assignment8/bin/partD/package-info.class create mode 100644 Week8/EclipseIDE/Assignment8/numbers.txt create mode 100644 Week8/EclipseIDE/Assignment8/src/module-info.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partA/IsReverse.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partA/package-info.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partB/Replace.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partB/package-info.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partC/CountNumbers.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partC/package-info.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partD/InsertArray.java create mode 100644 Week8/EclipseIDE/Assignment8/src/partD/package-info.java create mode 100644 Week8/SublimeText/CountNumbers.class create mode 100644 Week8/SublimeText/CountNumbers.java create mode 100644 Week8/SublimeText/InsertArray.class create mode 100644 Week8/SublimeText/InsertArray.java create mode 100644 Week8/SublimeText/IsReverse.class create mode 100644 Week8/SublimeText/IsReverse.java create mode 100644 Week8/SublimeText/Replace.class create mode 100644 Week8/SublimeText/Replace.java create mode 100644 Week8/SublimeText/numbers.txt diff --git a/Week8/EclipseIDE/Assignment8/.classpath b/Week8/EclipseIDE/Assignment8/.classpath new file mode 100644 index 0000000..1cd9d95 --- /dev/null +++ b/Week8/EclipseIDE/Assignment8/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Week8/EclipseIDE/Assignment8/.project b/Week8/EclipseIDE/Assignment8/.project new file mode 100644 index 0000000..5c86e38 --- /dev/null +++ b/Week8/EclipseIDE/Assignment8/.project @@ -0,0 +1,17 @@ + + + Assignment8 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Week8/EclipseIDE/Assignment8/.settings/org.eclipse.jdt.core.prefs b/Week8/EclipseIDE/Assignment8/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..910a770 --- /dev/null +++ b/Week8/EclipseIDE/Assignment8/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=14 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=14 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=14 diff --git a/Week8/EclipseIDE/Assignment8/bin/module-info.class b/Week8/EclipseIDE/Assignment8/bin/module-info.class new file mode 100644 index 0000000000000000000000000000000000000000..270cba67231716c1d4c6751268d9adad0126bf34 GIT binary patch literal 150 zcmX^0Z`VEs1_mnzE_MbcMh5QO{FKt1RNc(Hw0uSeuHgLAqU2P!%$!t41_2}~y{yEt zL`DWSU$AOn26muM$KvA5^t{~Eyb=px22Mr>PLLYCq{QOX1_lO3pdApv#J~(>Ffp(& TumWi@1~#xTBLhbRm;oUGe1aX| literal 0 HcmV?d00001 diff --git a/Week8/EclipseIDE/Assignment8/bin/partA/IsReverse.class b/Week8/EclipseIDE/Assignment8/bin/partA/IsReverse.class new file mode 100644 index 0000000000000000000000000000000000000000..545a9b65ca3ca06b88bcdec52ab43176c994d8c0 GIT binary patch literal 1789 zcmZ`(OK%%h6#kAqueeV0Y>HbaIJ6~xCFWHgb_=v2fq)a2xI}WZ8ru^y#j#yy62XEU zKcG^jEZ876u*n9bCJ3r5TZuKlf-PGFe0Q9rIF2iMwVBByUuJ^7W7*DJTwE1S$2_cAq zFmxEi$-50_WqY&iwC~#Gx+56PH!F61&2GDDe-{+ilcxiM0VlaM{GAuDpt0 zZF$aS7*R|zr{*?OywEXro0&Vb^l0zcn>iCN3ND_8y}j+$t4`a(G*dqbJZ`7UiEIc{ zxT4B(m6-9fA__t9av0|^q|U~}NFd1)+pU(E!>(^R7C2*F74;3??-EwijzYQJC3MnNCH$aE zSXB+Nu-GNsNY|9`qf&XLHKamL_#8s))dX8(jbAbOr?grEZ zQKF20faZfPB%fg*^$fbUN6sX7F8Q=03GO8iQ-|L{5AFqT{)mZWbS{-Vj8?VkoG<() zAkpOE_y7K>?GZ5OJD*^D%29}4lp$QB>v=j?!NfWaF^m!JfCY?_6U^}B7{(d?1xg2D zg-lbdzxl8X1qd~Pi=CJQHO6cKaxiQ>36+9cp`_`Bl1?&=Ldi4>CCe)0J4%a63Un$A z9xzFkR#@(`{GZjzu-P9ntNB`um^v|iGlfSQHnc)km#iUK^Jl#98>UL5u>-u6O89@P;oqW6Wrr4Hy3t?z+(<^M$A8^D4B zFd}AOfDioxslFL3QJ;z!J^JS(y68{92qrlJS@yoj?muAnAF|nx*zR4vz>jeWf8a9y zLR7~2=w8Q^e8#tR2Qk^@GrEr}{#31YMgpH8&*_*01C^IOK)A2~I;tn|jyE2VW$(bCtRbtWdKdyIy1^@s6 literal 0 HcmV?d00001 diff --git a/Week8/EclipseIDE/Assignment8/bin/partA/package-info.class b/Week8/EclipseIDE/Assignment8/bin/partA/package-info.class new file mode 100644 index 0000000000000000000000000000000000000000..951f65a0ecdfb3251caa3d6d39a76a273c3ffab3 GIT binary patch literal 111 zcmX^0Z`VEs1_mnzc6J6PMh2mR#G(>M{er~g?8Nj`-ORkSe0ByFMh1bb#Ii*FoW#6z yegCAa)Z`LI2Cm@z(xT*4x6GVWMg~D-9eNae^1=@gUX|19_YNiBLZH+4 zKKMuYV14O~PpuEwaU6Vf#?JWav*RD2e}G!Qv)NP%Jo&JD&%Nh6=ljmR=iZA+s9CYv?!7 z_fk14_jj7!RuTg^$5QIMtgL%6sMfFNZb^=nX2Wy0W-K^3Zy=@6b%HyI*QID9V6D~! zJe0&RE|NT0;|`^%!9<37N5wxP{!!AUTYSOplFYAd%mh2S<@z;+p7h#DeiLtSM+1Qj za9kF)_s&jzpI8;<$1=pd#yqc(ijffPtHp=S@ zXta3u_%}Gqaa0`j>~}Dq(1^g|U)*3og8yU-z_Ej~xEv2xB=`#=G>)n4PfYMQI`;^t zvjgLOU%|)@^cNpQ)j;;(;qyPTj|qwfiF?Q`>0?ZgfQcTCgG?$!*;X>xIL#T;q7z*K zc?z%6iV%MW-L#^N6DeBkFFrh0geH4ARP`m@5xTEZmGv!p_c8b+I{OHNw6lHV`?%1T zJ3w7$D8;3R&wmTi3~s3%W@4~ljU`*ul_0lGExlBcp`9n~6%vd3o)&4S zz5_#nQeI8^s5Bu;&x+D9jJK3VGE5u;)UIv)V3nd;v83t6k{&CTVzdpjSTc=b$(D(2 z&|{l)*>SD7XeZkN1nK;O0D?{0c1)sL0TLRQHA{X8y}0!MLzh)SGupgup+>Qw%Rc6~ zk0VbpA@(KOqoF-Xdn~l4Y4>X3`%uegBUd7gjrDgGO2rSp02Kvs2QL=Et99>SO!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--git a/Week8/EclipseIDE/Assignment8/src/partC/package-info.java b/Week8/EclipseIDE/Assignment8/src/partC/package-info.java new file mode 100644 index 0000000..2cf5023 --- /dev/null +++ b/Week8/EclipseIDE/Assignment8/src/partC/package-info.java @@ -0,0 +1 @@ +package partC; \ No newline at end of file diff --git a/Week8/EclipseIDE/Assignment8/src/partD/InsertArray.java b/Week8/EclipseIDE/Assignment8/src/partD/InsertArray.java new file mode 100644 index 0000000..da69f25 --- /dev/null +++ b/Week8/EclipseIDE/Assignment8/src/partD/InsertArray.java @@ -0,0 +1,60 @@ +//This code is written by Siwat Sirichai +package partD; +import partB.Replace; +//Utilizing the method arraycopy(Array a,int a_start_pos, Array b,int b_start_pos, length) +//This is kinda complicated, diagram attached. +public class InsertArray { + public static void arraycopy(int[] a, int apos,int[] b, int bpos, int length) { + for(int i=0;i=a.length-1) { //If pos => a.length just put a before b + arraycopy(a, 0, result, 0, a.length); + arraycopy(b, 0, result, a.length, b.length); + } + else { + arraycopy(b, 0, result, pos, b.length); //put in b first + arraycopy(a, 0, result, 0, pos); //put the first part of a in (part before b) + arraycopy(a, pos, result, pos+b.length ,a.length-pos); //put the second part of a in (part after b) + } + return result; + } + + + public static void main(String[] args) { + // TODO Auto-generated method stub + int[] a = { 1, 2, 3, 4}; + int[] b = { 5, 6, 7}; + int[] c = { 8, 9, 10, 11, 12}; + + System.out.print("Printing array a: "); Replace.printArray(a); + System.out.print("Printing array b: "); Replace.printArray(b); + System.out.print("Printing array c: "); Replace.printArray(c); + + System.out.println("Now calling inserts!"); + System.out.println("------------------------"); + int[] d = insert(a,b,1); + int[] e = insert(a,b,4); //ERROR + int[] f = insert(b,a,0); + int[] g = insert(c,a,3); + int[] h = insert(c,a,-1); + int[] i = insert(c,a,7); //ERROR + + System.out.print("Printing array a, expecting {1,2,3,4} : "); Replace.printArray(a); + System.out.print("Printing array b, expecting {5,6,7} : "); Replace.printArray(b); + System.out.print("Printing array c, expecting {8,9,10,11,12} : "); Replace.printArray(c); + System.out.print("Printing array d, expecting {1,5,6,7,2,3,4} : "); Replace.printArray(d); + System.out.print("Printing array e, expecting {1,2,3,4,5,6,7} : "); Replace.printArray(e); + System.out.print("Printing array f, expecting {1,2,3,4,5,6,7}: "); Replace.printArray(f); + System.out.print("Printing array g, expecting {8,9,10,1,2,3,4,11,12} : "); Replace.printArray(g); + System.out.print("Printing array h, expecting {1,2,3,4,8,9,10,11,12} : "); Replace.printArray(h); + System.out.print("Printing array i, expecting {8,9,10,11,12,1,2,3,4} : "); Replace.printArray(i); + + } + +} diff --git a/Week8/EclipseIDE/Assignment8/src/partD/package-info.java b/Week8/EclipseIDE/Assignment8/src/partD/package-info.java new file mode 100644 index 0000000..420b6aa --- /dev/null +++ b/Week8/EclipseIDE/Assignment8/src/partD/package-info.java @@ -0,0 +1 @@ +package partD; \ No newline at end of file diff --git a/Week8/SublimeText/CountNumbers.class b/Week8/SublimeText/CountNumbers.class new file mode 100644 index 0000000000000000000000000000000000000000..ae66ed525a0386e49a987174be12319a094d1d32 GIT binary patch literal 1590 zcmaJ>&r=*l6#kn1F)$3jnGgcR0TX4xWg`kI8;oWRW(_RSrAS3i!_vTnrDtoWmx4Q0 zsftGr#%s!|T)f0XNF^43fd7a$tGroOMf_%GQ`rdRVY+)>f3M&BzW2I+`{(&FfH{0) zq6IMnaSI6~1-kFKdv2!es;$iO`aN0F0?DhM^7N+yvGLTZfmVT@I;f_-a;8{vm6BBh zrhrv9dwyoYE6Y|`0`01{yDqE2l-}1S+RzzB=@PKV7hlII>Z+%u%%ko@&-O5+cR8P=AvJ#mSo6*9nq})R7joGyzcut&{emxB=xqx5p*SS z!^8rrV63p1&hAQNu;0S#axg1s*oHWCIu-dec=KWf@#r^!=S$C3~7% zljRM^m4k{r1KvzEx?|bqc4!=tbIawTr)9Pkw**ovEK*cO$KPbtwA|voavBZD8oJ7v zo|$t5n=~KZ$XwYC0vQ-62wXlT!CA}<+!na_|4?>%Bm+iyGg{d0Knx;$J2-yKzY)%Y zb7JBM;t3aQLXP1!jeG;pFgvDt*3u;Y(#K5ZwaW|MYu=qDs8&tZb3e;@vt;3(Bj)&+bJTX2DC4%NdCAa=s6 nlVM;6;{e!yu?8`GUU$5X9OqU>|AOCFSmd9{)e@HRH3t6$yflAB literal 0 HcmV?d00001 diff --git a/Week8/SublimeText/CountNumbers.java b/Week8/SublimeText/CountNumbers.java new file mode 100644 index 0000000..bed8594 --- /dev/null +++ b/Week8/SublimeText/CountNumbers.java @@ -0,0 +1,30 @@ +//This code is written by Siwat Sirichai +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; +public class CountNumbers { + + public static void main(String[] args) { + try { //Since java.io.File throws FileNotFoundException, a try-catch block is neccessary. + Scanner sc = new Scanner(new File("numbers.txt")); //This create a scanner with file "number.txt" as an input + int length = 0; //define array length initialy at zero + for(length = 0;sc.hasNextInt();length++)sc.nextInt(); //Use File Scanner to find the number of elements in the file + int[] int_array = new int[length]; //Create an array with length number of elements + sc = new Scanner(new File("numbers.txt")); //Send the Scanner's cursor to the top of the file + for(int i = 0;iv)count++;//This is called a for-each loop, it will loop for a.length iteration, + return count; + } + +} diff --git a/Week8/SublimeText/InsertArray.class b/Week8/SublimeText/InsertArray.class new file mode 100644 index 0000000000000000000000000000000000000000..481717f33469cd14bcea094433e96a8283e1ec73 GIT binary patch literal 1802 zcmaJ>OK%%h6#lMf#xtHc#3XT>G){0*n%bTjC(f&>Q%XvpU`S&iD3av`89PIm;@FYn zP%4DjAhGO{6+*Bn%NC(Fsw#^$;t%i#Sg>V>D&U-Jhx$>ltT~T+zVp8K=f55`0c7!( zi2xKGY8V=V0+E~U$L?Ikt?tj|OEXBD( zT&vgJ+X5k%X}NYtyqPHGa`ew7cS3j$Lpma1Jdfe75Zkwp8r}hUt{qdL=%x(r*XG`? z`_;yFqwcu}YX(LIhNZ@@?#E?_xSNfeID@k~#=;oKIf0R9UEsFLK4ftmg^O4+!97yI>P*3SxzZq;tZ%WkE@ znftO;N7I~mB8((wt;;}_ssT%2%=wQWH{A&%jX9b|%MCS~(xUz*i#Y=sfkbbI?6~*I zAq|j2f10ru>_vO&vp6TVC@|Y&UFx!4wpZ*+E!$-Qr^mM3WxHx$wlni~CSzw7T98Wu z=^n^l7bIiL0G%ma?#FmN7+F9I*^0B)pV|ligW<|w5?Jm@ZNCe0T1_jr&Z=JShkn=v zZMWDyb@8+z*ZQG;7qk;%cZ^Cv-Kg!+J`QdARd4I~pybuxb4wM{3~o2v@<%t^Ln-UH zE)Xc@2yo!~Re>{!;Hha5vTrYdqeRdM*xV>qUW6RQEhTJ71bto)A=tnarf`v*+oFQ z;P;0e#h~L=;z9^Kfg=9I7_qeRZLjyqM5SXl)wG(skIk*v*BG}HN3ohG&{K+IHB-#p z#d<8&RQJBcI4KpWBQr+H(-{(Crx+#1*cdBzQ_a{ONzT20GfPuZoR0yMiW@+bzBBZc zr7(m=M6iw#eN=;VEzmD!t6o?u4DYm-xie4Uyhny)ZQ<$Zvd4tw6PpvQFJoa$` zHPYU~MSP9~zNB~b4vpk1Soj7uzNek}k+$Y1%;Ohi@GBPZ8;$D^EYYeii$Sc2b6BOZ J=a.length-1) { //If pos => a.length just put a before b + arraycopy(a, 0, result, 0, a.length); + arraycopy(b, 0, result, a.length, b.length); + } + else { + arraycopy(b, 0, result, pos, b.length); //put in b first + arraycopy(a, 0, result, 0, pos); //put the first part of a in (part before b) + arraycopy(a, pos, result, pos+b.length ,a.length-pos); //put the second part of a in (part after b) + } + return result; + } + + + public static void main(String[] args) { + // TODO Auto-generated method stub + int[] a = { 1, 2, 3, 4}; + int[] b = { 5, 6, 7}; + int[] c = { 8, 9, 10, 11, 12}; + + System.out.print("Printing array a: "); Replace.printArray(a); + System.out.print("Printing array b: "); Replace.printArray(b); + System.out.print("Printing array c: "); Replace.printArray(c); + + System.out.println("Now calling inserts!"); + System.out.println("------------------------"); + int[] d = insert(a,b,1); + int[] e = insert(a,b,4); //ERROR + int[] f = insert(b,a,0); + int[] g = insert(c,a,3); + int[] h = insert(c,a,-1); + int[] i = insert(c,a,7); //ERROR + + System.out.print("Printing array a, expecting {1,2,3,4} : "); Replace.printArray(a); + System.out.print("Printing array b, expecting {5,6,7} : "); Replace.printArray(b); + System.out.print("Printing array c, expecting {8,9,10,11,12} : "); Replace.printArray(c); + System.out.print("Printing array d, expecting {1,5,6,7,2,3,4} : "); Replace.printArray(d); + System.out.print("Printing array e, expecting {1,2,3,4,5,6,7} : "); Replace.printArray(e); + System.out.print("Printing array f, expecting {1,2,3,4,5,6,7}: "); Replace.printArray(f); + System.out.print("Printing array g, expecting {8,9,10,1,2,3,4,11,12} : "); Replace.printArray(g); + System.out.print("Printing array h, expecting {1,2,3,4,8,9,10,11,12} : "); Replace.printArray(h); + System.out.print("Printing array i, expecting {8,9,10,11,12,1,2,3,4} : "); Replace.printArray(i); + + } + +} diff --git a/Week8/SublimeText/IsReverse.class b/Week8/SublimeText/IsReverse.class new file mode 100644 index 0000000000000000000000000000000000000000..b918ab2dd8b6d80e7fa7b332447cddf50190849b GIT binary patch literal 1940 zcmaJ?&2Jk;6#q^3W7e+Qn0%FOo78QSV0*VQ-xMb;w1&_?oGne&%FStQPtt9iU9-E6 z2xtBU1RM|u4qS2pBtTW=3lf#M@;7kfj)cU=+ub;c6{m-J^XAR(eaxFTZ+`ptQ5QfN zx6>Gc#35&(KxN22w72b2%XT+PR{f!9gbeC}<2vCr1}R^-n}&uIM>>NO$n@Zy&}o&f z`@X#s5L|rFv0KFO{MypmQsI6Ir!dTs&EOe~^i*OGt2;p`w#cy8AwT2Gv2VvK-SQnb zTn&9;Z_TGMhH;LG3{FQ5Q%k{Zu`T>S5byN(5ju;W!5N%oIK5?Wii+np?C_owJ|Hd# zZ8xNV#`E_JiI2p4NNzUB!6c?Q&S#Lr1%}Z9LC{&+QAjN}GIG>J;qC|+^btxW5h)^a zM3jiA5#bThpfku7uSu~FFFUSS>1@@7f5)!3NOE#Dv>TgMyB)7N<`{<7mPldCcF6BU zer=FrhV-h}@f%{%iHw}uPtRO*4$Afo&kKXlx7$?_KJc2su!>jGcona4T!}LFI>YqA zojdNfw<$`LdrD1`#6`Oidj1Z>XNOO|2TY9KwB2S)1k=l&x7lgWAC2>nq)+kAPFoCs zA3kYPh4Y6mZqG!;ZnajOP|RzXXPDhDhP-Xo3*{U$bK=7`Rj_F0LN8YrxzO(j4OjcH zb+b_@ABC<{1rzp-KCJyz>~)5jgBY5o7-TmIq0$ExX7hOH+kFuxrDX?!2sl`#4>du1y-MQP1>cFkmj6e|3Kxq%>KqiijXBdp9IN1 zp%67X#nr6(I9-!ut0pT}O`)NxR*iG3rfJr4vZ>J~2^88;3BYM+vQ_QZl=?JRvix|n zwX7;xWjTS6o=grDau9otjMK=fvQ<`CS!HGZJx&^whtWrP7Wfh8Xl-7O*B5(hBUxYS zt#w&fV#M^mMA79~GSicodxF`XKv#7hL!LX37_lJV6BxQ03ktE|pbi%40|G{=OvdQv z8^=9N;3KMuFDT@%pyL~y#SgUm3#RZp&f^dI5&oh-LBmCM2A7zDX|{k_D!LcqYkm}9&Ja!eOudM&1J#`H!^--_vCOmD{YT`ZG!nl!7h@ILha0m}=^KL7v# literal 0 HcmV?d00001 diff --git a/Week8/SublimeText/IsReverse.java b/Week8/SublimeText/IsReverse.java new file mode 100644 index 0000000..3cf02dc --- /dev/null +++ b/Week8/SublimeText/IsReverse.java @@ -0,0 +1,35 @@ +//This code is written by Siwat Sirichai +import java.util.Arrays; + +public class IsReverse { + + public static boolean isReverse(int[] a, int[] b) { + if (a==null&&b==null)return true; //Special Case #1: if a and b is null, result: true, return right away to prevent NullPointer exception. + if((a==null&&b!=null)||(a!=null&&b==null))return false; //Special Case #2: if only one of a or b is null, result: false, return right away to prevent NullPointer exception. + if (a.length != b.length)return false; //Special Case #3: if the length of a and b is not equal, result: false, return right away to prevent ArrayIndexoutofBound exception. + for(int i = 0;iYxd6g>~mc*bLgOcN3sVuuNk#C9B;1e}1AQV1=nbyIc6f_2rebH`(vCah}9^X|Rx+D@~=_Y;rNVN#W69>8#pq%wjdkX;|+DG=a1KSq+U=+Z?+yd zb+6G7o$a0+CulmpSHC+cH(HbVf5u5 zdTB|}D+<#`(DlRMz7E0Ce@C%9hp~|i&ZSFkws!b52iJq9zuDcZ`R$LqT7#8=t&Ug! zY{T1+a&6BGnhK-Y?Kjzne%NYt+jaj|AkC@BCPi^Aoio9Ij(jxGD~R*@F0%|*#Z}LL z1NDr7!gXF{8*E6(!(%MaJBYCvn9Tn`_|w?6O#a1VoXTg4<6pwaXVUJYn0oT}%ly-@ z^*XPkWa4a&i_;Va#<-q^i5sjYp~e4zQuglzB*fYg&lltosaMHkeGTIP1J7bB<3e_h zX@0zTfFY*Z&SNB57#cmm+m95fe~Hj+J`vu=GzS9%lzkEw2FW>uVSdy68x|NZP~jDv z?(0d4o{65GRov|9QNOW0&V%XN)^}Dlrnyy3cdL5bt;QJ}rdu@)w`xmb8{Dx?ZrKUV zUAI&H27+|{!Ulp(#&%q~dJWQ=keVfzr0#C~|JF@a(TqNCU#Q_$bUCVV9@Xq~WF$V% zxDdrtjOU_whVhsdB{@m-D49LL+^l9VJxA%|f@!bHI%n7$vW{t*8Lql%8xjb`B{s-f z=9E6|65~GYRmOeVWnt>mz9Wgy{%grk_?&=o8ZwOrefxxt{)%q;p4Rz^=J^@t@hdLi z6{hefW|Yns+W>NEgfFrTX4Mp5TtyVsB1&o%7u6=_)g8W>c5z8{Q0BvaFZ9j({{S2S BTwMSF literal 0 HcmV?d00001 diff --git a/Week8/SublimeText/Replace.java b/Week8/SublimeText/Replace.java new file mode 100644 index 0000000..d7920a9 --- /dev/null +++ b/Week8/SublimeText/Replace.java @@ -0,0 +1,55 @@ +//This code is written by Siwat Sirichai +public class Replace { + + public static int[] replace(int[] a, int v, int v2) { + if (a==null)return a; //If a is a null pointer, return immediately to prevent a NullPointerException + for(int i = 0; i < a.length;i++) //loop from 0 to the length of array a, number of completed iteration is stored in i (type int) + if(a[i]==v)a[i]=v2; //if the value of a at index i is equal to v, replace it with v2 + return a; //Return the replaced array a + + } + + public static void printArray(int[] a) { + if(a==null) { + System.out.println(); //Create a newline to make the format looks uniform + return; //If a is a null pointer, return immediately to prevent a NullPointerException + } + //NOTE: return; (a return statement without a return value) in a method with no return type will break out of the method. + for(int i = 0;i