Problem about using serial to read the string

hallo,

i am recently using Arduino to learn about coding method. i try many way to use the serial port to read the string i sent.

i am trying to send a 3 digit number to the serial port to arduino. and arduino will send it back to the computer.

int R[2];
  int P;

  void setup() {
  Serial.begin(9600);
  Serial.print("Plz input number(000~999):");
}

void loop() {
  if (Serial.available() > 0) {
    for(int i;i<2;i++)
    R[i]=Serial.read();
    P = 100*R[0]+10*R[1]+R[2];
   Serial.write(P);
   Serial.write('\n');
}
}

But the outcome is that by using the Serial monitor to send and receive data, i type in the number "123" and the result is that "9
�"

if (Serial.available() > 0) {
for(int i;i<2;i++)
R*=Serial.read();[/quote]*
First you check if there is AT LEAST ONE serial data available. Then you try and read THREE. How do you think this is going to work?
Remember Serial is S. L. O. W. Your Arduino can run that loop thousands of times before the second character arrives.
Look for Robin's Serial Input Basics post in the Programming section.
Then use the auto-formatter on the tools menu to get your indentation correct. Using a for() loop without the braces ({}) is usually a bad idea for readability.

Trying to read the third element of a two element array isn't being very sensible.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

AWOL:
Trying to read the third element of a two element array isn't being very sensible.

Nor is trying to write to it.

The writing index is not initialized, so the for loop could perform an unexpected number of writes to unexpected locations.

    for(int i;i<2;i++)

thank you so much about suggesting the solution on this application

i will try the Serial Input Basics example, thank you so much

i will try to improve my programming skill.