Answer
See below.
Work Step by Step
(a) Let $n$ be any integer,
case1: $n=3m+0$, we have $n^2=9m^2=3(3m^2)$, thus $k=3m^2$
case2: $n=3m+1$, we have $n^2=9m^2+6m+1=3(3m^2+2m)+1$, thus $k=3m^2+2$
case3: $n=3m+2$, we have $n^2=9m^2+12m+4=3(3m^2+4m+1)+1$, thus $k=3m^2+4m+1$
As the remainder can only be $0,1,2$, in any case, we can write $n^2$ in the form of $3k$ or $3k+1$
(b) Let $n$ be any integer,
case1: $n$ mod $3=0$, we have $n^2=9m^2=3(3m^2)$, thus $n^2$ mod $3=0$,
case2: $n$ mod $3=1$, we have $n^2=(3m+1)^2=9m^2+6m+1=3(3m^2+2m)+1$, thus $n^2$ mod $3=1$,
case3: $n$ mod $3=2$, we have $n^2=(3m+2)^2=9m^2+12m+4=3(3m^2+4m+1)+1$, thus $n^2$ mod $3=1$,
As the remainder can only be $0,1,2$, in any case, we have $n^2$ mod $3=0$ or $n^2$ mod $3=1$