C # console application console statement accepts multiple data inputs at the same time

Source: Internet
Author: User

I. Differences between console. Write () and console. writeline ()

The former outputs no line breaks.

Ii. Differences between console. Read () and console. Readline ()

1 'console. read () console. the Readline () method reads information from the keyboard. The only difference is the console. the read () method is used to obtain the ASCII value of any user input value (which can be any alphanumeric value. console. what about Readline? Stores the obtained data in a string variable.

2 'console. Read () indicates reading strings from the keyboard without line breaks. Console. Readline () indicates reading strings from the keyboard and wrapping them.

3. Accept multiple data inputs at the same time

 

Solve the problem through system functions using Arrays: for example:

Example 1: create a one-dimensional integer array, initialize the array by receiving the 10 numbers entered by the user, and print them in reverse order.
Implemented Using console. Readline () and string Separator

Static void main (string [] ARGs)

{

Console. writeline ("Enter ten numbers and separate them with spaces :");

String string1 =
Console. Readline ();

String [] string2 = system. Text. regularexpressions. RegEx. Split (string1, @ "[] + ");

String [] result = newstring [10];

For (INT I = 0; I <10; I ++)

{

Result [I] = (string2 [10-I-1]);

Console. Write (result [I] + "");

}

}

I. Differences between console. Write () and console. writeline ()

The former outputs no line breaks.

Ii. Differences between console. Read () and console. Readline ()

1 'console. read () console. the Readline () method reads information from the keyboard. The only difference is the console. the read () method is used to obtain the ASCII value of any user input value (which can be any alphanumeric value. console. what about Readline? Stores the obtained data in a string variable.

2 'console. Read () indicates reading strings from the keyboard without line breaks. Console. Readline () indicates reading strings from the keyboard and wrapping them.

3. Accept multiple data inputs at the same time

 

Solve the problem through system functions using Arrays: for example:

Example 1: create a one-dimensional integer array, initialize the array by receiving the 10 numbers entered by the user, and print them in reverse order.
Implemented Using console. Readline () and string Separator

Static void main (string [] ARGs)

{

Console. writeline ("Enter ten numbers and separate them with spaces :");

String string1 =
Console. Readline ();

String [] string2 = system. Text. regularexpressions. RegEx. Split (string1, @ "[] + ");

String [] result = newstring [10];

For (INT I = 0; I <10; I ++)

{

Result [I] = (string2 [10-I-1]);

Console. Write (result [I] + "");

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.