Home > Net >  C # small white sample record 1: the user to enter two Numbers, and for all integers between two Num
C # small white sample record 1: the user to enter two Numbers, and for all integers between two Num

Time:10-17

The small white wrote himself, please advise,
using System;
The class Calculate
{
The static void Main ()
{
Int a=0;
int b=0;
Int all=0;
While (true)
{
Bool s=true;
Try
{
Console. WriteLine (" please enter the first number: ");
A=(int) Convert. ToDouble (the Console. The ReadLine ());
Console. WriteLine (" please enter the second number: ");
B=(int) Convert. ToDouble (the Console. The ReadLine ());
}
Catch
{
Console. WriteLine (" input is incorrect, please enter again ");
S=false;
}
If (s) break;
}
Console. WriteLine (" integer is between two Numbers: {0}, ", Math. Abs (a - b) - 1);
If (a{
For (int I=a + 1; i{
Try
{
If (b - a> 1)
Checked {all +=I; }
The else
All=0;
}
Catch
{
Console. WriteLine (" beyond the scope of!" );
return;
}
}
}
The else
{
For (int I=b + 1; i{
Try
{
If (a - b> 1)
Checked {all +=I; }
The else
All=0;
}
Catch
{
Console. WriteLine (" beyond the scope of!" );
return;
}
}
}
Console. WriteLine (" between them and for {0} ", all);
}
}

CodePudding user response:

Downstairs code 10 words to you

CodePudding user response:

 
Int Num1=0;
Int Num2=0;
Int Sum=0;
List NumList=new List (a);
Console. WriteLine (" please enter the first digit: ");
Num1=(int) Convert. ToDouble (the Console. The ReadLine ());
Console. WriteLine (" please enter the second digit: ");
Num2=(int) Convert. ToDouble (the Console. The ReadLine ());
If (Num1 & gt; Num2)
{
For (int I=Num2 + 1; I & lt; Num1. I++)
{
The Sum +=I;
NumList. Add (I);
}
}
Else if (Num1 & lt; Num2)
{
For (int I=Num1 + 1; I & lt; Num2; I++)
{
The Sum +=I;
NumList. Add (I);
}
}
Else if (Num1==Num2)
{
Sum=0;
}
If (Num1==Num2)
{
Console. WriteLine (" the integers between two number is empty, and zero!" );
}
The else
{
StringBuilder builder=new StringBuilder();
The foreach (var item in numList)
{
Builder. AppendFormat (item. The ToString () + ", ");
}
Console. WriteLine (" integer is between two Numbers: "+ builder. The ToString ());
}
Console. WriteLine (" {0} {1} between integer and {2} ", Num1, Num2, Sum);
Console.ReadKey();

CodePudding user response:

 

The static void Main (string [] args)
{
Game ();
Console.ReadKey();
}
///& lt; Summary>
///get a double-digit
///& lt;/summary>
///& lt; Param name="Num1 & gt;"
///& lt; Param name="Num2" & gt;
///& lt; Returns>
Public static bool GetNum (ref int Num1, ref int Num2)
{
Double the result=0;
Console. WriteLine (" please enter the first digit: ");
String a=Console. ReadLine ();
Bool isNum1=double. TryParse (a, out result); Can//into digital
Console. WriteLine (" please enter the second digit: ");
String b=Console. ReadLine ();
Bool isNum2=double. TryParse (b, out result); Can//into digital
If (isNum1 & amp; & IsNum2)
{
Num1=(int) Convert. ToDouble (a);
Num2=(int) Convert. ToDouble (b);
return true;
}
The else
{
return false;
}
}
///& lt; Summary>
///digital sum
///& lt;/summary>
///& lt; Param name="Num1 & gt;"
///& lt; Param name="Num2" & gt;
Public static void Summation (int Num1, int Num2)
{
Int Sum=0;
List NumList=new List (a);
If (Num1 & gt; Num2)
{
For (int I=Num2 + 1; I & lt; Num1. I++)
{
The Sum +=I;
NumList. Add (I);
}
}
Else if (Num1 & lt; Num2)
{
For (int I=Num1 + 1; I & lt; Num2; I++)
{
The Sum +=I;
NumList. Add (I);
}
}
Else if (Num1==Num2)
{
Sum=0;
}
If (Num1==Num2)
{
Console. WriteLine (" the integers between two number is empty, and zero!" );
}
The else
{
StringBuilder builder=new StringBuilder();
The foreach (var item in numList)
{
Builder. AppendFormat (item. The ToString () + ", ");
}
Console. WriteLine (" integer is between two Numbers: "+ builder. The ToString ());
}
Console. WriteLine (" {0} {1} between integer and {2} ", Num1, Num2, Sum);
}
///& lt; Summary>
///whether or not to continue
///& lt;/summary>
///& lt; Param name="Num1 & gt;"
///& lt; Param name="Num2" & gt;
Public static void Again (int Num1, int Num2)
{
Console. WriteLine (" whether or not to start the program?" );
Console. WriteLine (" resume 1:0: refused to start ");
String isOk=Console. ReadLine ();
If (isOk=="1")
{
Game ();
}
Else if (isOk=="0")
{
Console. WriteLine (" calculation over!" );
}
The else
{
Again (Num1, Num2);
}
}

Public static void Game ()
{
Int Num1=0;
Int Num2=0;
If (GetNum (ref Num1, ref Num2))
{
A Summation (Num1, Num2);
Again (Num1, Num2);
}
The else
{
Console. WriteLine (" please input specification Numbers again!" );
GetNum (ref Num1, ref Num2);
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related