0
How to square an array?
I am to make a code that squares the inputted integer. The rules is that: 1. The input consist of only one integer 2. The array element should only contain 5 values 3. The output should result with 3 integer places Ex.1 Input: 1 Output 001 004 009 016 025 Ex2: Input: 8 Output: 064 081 100 121 144 Below is my attempted code, but I don't know how to put 3places https://code.sololearn.com/ca19A24a10A2
1 Antwort
0
remove the "int" in first for loop coz it is unnecessary, int keyword is only used to declare an integer. In your case, you already declared num, so no need of that "int".
About that 3 integer places, you can convert Integer to String and format it to add 2 or 1 zero before the answer.