Home > Net >  Help everybody look at me what's wrong with this code, run not to come out.
Help everybody look at me what's wrong with this code, run not to come out.

Time:09-25

In VS, I want a result, the input character, if it is digital, to join the array, if it is a direct return, output "input is empty", if it is other characters, output "illegal characters enter again", but now as a result, the input character, carriage returns, in the input character to normal cycle, just learning c # can't also see have what problem, please help
using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;

The namespace firstSubject
{
Class Program
{
The static public bool buy (string num)
{
Try
{
The Convert. ToInt32 (num);
return true;
}
Catch
{
return false;
};
}
The static void Main (string [] args)
{
Int [] ArrayList=new int [10].
int i, j;
int sum=0;
For (I=0; i <10; I++)
{
Console. WriteLine (" please input array ArrayList first {0} element value: ", I);
String myString=Console. ReadLine ();
If (buy (Console. ReadLine ()))
{
ArrayList. [I]=the Convert ToInt32 (myString);
}
Else if (myString. Length==0)
{
Console. WriteLine (" do not enter an empty string, please enter again. ");
I -;
}
The else
{
Console. WriteLine (" illegal input, please input again. ");
I -;
};
}
For (j=0; J & lt; 10; J++)
{
Sum=sum + ArrayList [j];
}
Double business=sum/10;
Console. WriteLine (" array ArrayList average is: {0: F4} : ", business);
Console.ReadKey();
}
}
}

Please help to run, solve, thank you

CodePudding user response:

Remove one of the,
String myString= the Console. ReadLine () ;
If (buy ( Console. ReadLine ()))
{
ArrayList. [I]=the Convert ToInt32 (myString);
}


:
String myString=Console. ReadLine ();
If (buy ( myString ))
{
ArrayList. [I]=the Convert ToInt32 (myString);
}

CodePudding user response:

reference 1st floor github_36000833 response:
remove one of them is ok,
String myString= the Console. ReadLine () ;
If (buy ( Console. ReadLine ()))
{
ArrayList. [I]=the Convert ToInt32 (myString);
}


:
String myString=Console. ReadLine ();
If (buy ( myString ))
{
ArrayList. [I]=the Convert ToInt32 (myString);
}

Brother, you are really amazing, what is this principle, why to enter twice before can continue to determine cycle?

CodePudding user response:

reference solitary fang not up on the second floor response:
Quote: refer to 1st floor github_36000833 response:
remove one of them is ok,
String myString= the Console. ReadLine () ;
If (buy ( Console. ReadLine ()))
{
ArrayList. [I]=the Convert ToInt32 (myString);
}


:
String myString=Console. ReadLine ();
If (buy ( myString ))
{
ArrayList. [I]=the Convert ToInt32 (myString);
}

Brother, you are really amazing, what is this principle, why to enter twice before can continue to determine cycle?

Ahem, because you used the two readline, according to your original writing, you enter the first line by readline is assigned to a value, before you enter the second line into the select statement, understand the use of debugging see problems,

CodePudding user response:

Because twice your code is input into the circulation and
  •  Tags:  
  • C#
  • Related