ConversionTable
Initially, I forgot to add i!=1 in the if statement. Therefore, the program will output a “\n” when i=1. Drawing trace table can help me to find out this kind of problem in the future.
PrimeNumber
Attention HERE! There are two new methods involved: Break Statement & Boolean.
The break statement has two usages: inside loop or inside switch.
When the break statement is encountered inside a loop, the loop is immediately terminated and the program will go to the next statement following the loop. In this case, if (i%j==0), break statement will be invoked. Then it will directly terminate the second forLoop statement for(int j=2;j<i;j++){}.
Boolean only has two possible value: true or false. While I was programming, a simple “=” completely altered my result. You can see that the sentence boolean prime=false has one “=” while if(prime==true){} has “==”(two equal marks).
Why? That is because what inside if statement is logical expression, we should always write like if(x==0). However, boolean prime=false is an declaration and assignment statement while only requires one “=”.
Mutiplesof3
Stars
GradeAverage
I created an int Array called anArray which contained num index numbers. Then ask the user to enter the value of each index within Array anArray. sum+=anArray[i]; means sum=sum+anArray[i].