Sample code as follows: Dim strValue As String = yourValue.ToString() If strValue.Length < 5 Then ' to 1 Debug.WriteLine( strValue.Length.ToString() ) ' ' to 2 Dim chrArray As Char() = strValue.ToCharArray() For Each chr As Char In chrArray Debug.WriteLine( chr ) Next
' to 3 Array.Reverse( chrArray ) For Each chr As Char In chrArray Debug.WriteLine( chr ) Next
End If
C# string strValue = yourValue.ToString(); if( strValue.Length < 5 ) { ' to 1 Debug.WriteLine( strValue.Length.ToString() ) ;' to 2 char[] chrArray = strValue.ToCharArray(); for( int i=0; i < chrArray.Length; i++ ) Debug.WriteLine( chr );' to 3 Array.Reverse( chrArray ); for( int i=0; i < chrArray.Length; i++ ) Debug.WriteLine( chr ); }
int i;//正整数 ①求它是几位数; i.ToString().Length(); ②分别输出每一位数字; foreach(char c in i.ToString()) { Console.WriteLine(c); } ③按逆序输出各位数字。 for(int index = i.ToString().Length()-1;index--;index>=0) { Console.WriteLine(i[index]); }
Dim strValue As String = yourValue.ToString()
If strValue.Length < 5 Then
' to 1
Debug.WriteLine( strValue.Length.ToString() ) ' ' to 2
Dim chrArray As Char() = strValue.ToCharArray()
For Each chr As Char In chrArray
Debug.WriteLine( chr )
Next
' to 3
Array.Reverse( chrArray )
For Each chr As Char In chrArray
Debug.WriteLine( chr )
Next
End If
string strValue = yourValue.ToString();
if( strValue.Length < 5 )
{
' to 1
Debug.WriteLine( strValue.Length.ToString() ) ;' to 2
char[] chrArray = strValue.ToCharArray();
for( int i=0; i < chrArray.Length; i++ )
Debug.WriteLine( chr );' to 3
Array.Reverse( chrArray );
for( int i=0; i < chrArray.Length; i++ )
Debug.WriteLine( chr );
}
1、要判断是不是正数(大于或小于零)
2、要判断是不是整数(很多方法,可以用IndexOf('.'),也可以用for等等)
3、然后才是他的代码(只能选C#部分,因为这是C#论谈,哈哈)
1、要判断是不是正数(大于或小于零)
2、要判断是不是整数(很多方法,可以用IndexOf('.'),也可以用for等等)你用int.Parse处理,这很简单,加上try-catch即可。
string s;
try
{
i=(int)Console.ReadLine();
}
catch(Exception)
{
Console.write("0位/不合法");
break;
}
finaly
{
s=i.Tostring();
}
Console.Write(s.length.Tostring);
.........
.........
string s;
try
{
i=(int)Console.ReadLine();
}
catch(Exception)
{
Console.write("0位/不合法");
break;
}
finaly
{}
s=i.Tostring();
Console.Write(s.length.Tostring);
.........
.........
①求它是几位数;
i.ToString().Length();
②分别输出每一位数字;
foreach(char c in i.ToString())
{
Console.WriteLine(c);
}
③按逆序输出各位数字。
for(int index = i.ToString().Length()-1;index--;index>=0)
{
Console.WriteLine(i[index]);
}
string str = Console.ReadLine();
if(Convert.ToInt32(str)>=0&&(Convert.ToInt32(str)<100000))
{
int strLen = str.Length;//计算是几位数;
for(int j=0;j<str.Length;j++)//分别输出个位数;
{
Console.WriteLine(str[j]);
}
for(intj=Length-1;j>=0;j++)//逆序输出;
{
Console.WriteLine(str[j]);
}
}
catch
{
Console.WriteLine("Input is wrong");
return;
}
to
1、要判断是不是正数(大于或小于零)
2、要判断是不是整数(很多方法,可以用IndexOf('.'),也可以用for等等)你用int.Parse处理,这很简单,加上try-catch即可。还讨论什么啊。答案都在