locked
VB code RRS feed

  • 問題

  • How to product this code as shown below:

    If I enter "5" and "10" in the console screen, it display
    5 *****
    10 **********

    Whatever I enter any positive numbers, the screen will display the asterisk partern and depend on the number input.

    Please tell me the method using VB code to handle this program.

     

    2008年11月2日 12:19

解答

  • First you hae to define the input character indicating the end of the integer you've input, e.g. your program will start to print out the asterisk when it reads <space>, i.e. the integer 10 will be interpreted as 3 characters: "1", "0", " ".  Once you defined the delimiter (i.e. <space>), you can then use Console.Read() to read one character at a time and if it does not equal to the delimiter you defined, then append the character to a string, otherwise convert the string to integer and then print out the asterisk where the number of asterisk is equal to the integer you got.

    2008年11月2日 12:30

所有回覆

  • First you hae to define the input character indicating the end of the integer you've input, e.g. your program will start to print out the asterisk when it reads <space>, i.e. the integer 10 will be interpreted as 3 characters: "1", "0", " ".  Once you defined the delimiter (i.e. <space>), you can then use Console.Read() to read one character at a time and if it does not equal to the delimiter you defined, then append the character to a string, otherwise convert the string to integer and then print out the asterisk where the number of asterisk is equal to the integer you got.

    2008年11月2日 12:30
  • I can only display:

    *

    *

    *

     

    How to deal with ?

    ***

     

    my code is:

    number(0) = 3

    Do
          Console.WriteLine(number(0) + "*")
     Loop While (number(0) < 0)

    2008年11月2日 13:57
  • Try Console.Write() instead of Console.WriteLine()

     

    2008年11月2日 14:00
  • the program is fix now, thank you.

     

    The other question is "how to count the total numbers of numbers that is saved in a file.

    The file contains:

    3

    9

    100

    4

    2

    99

    222

     

    There are 7 numbers in the file, how to count them and print out?

     

    2008年11月2日 14:20
  • 1. Initialize an integer collection (List<Of Integer>)

    2. Read the file line by line

    3. Check each line is an integer or not

    4. If it is an integer, add the integer to the integer collection created at step (1)

    5. Check the "Count" property of the integer collection to get the total number of integers stored

    6. Use a For loop to print the integers out.

    2008年11月2日 14:30
  • My file contains:

    100

    3

    7

    10

     

     

    my code is :

    For i As Integer = 0 To number(4)
                If (i = number(0)) Then
                    result = number(0)
                    Console.WriteLine(result)

    End If

            Next

     

    why can't display larger than 10? for example, 100 can't be displayed but 1-10 can display.

     

    2008年11月2日 15:25
  • What are the items stored in number()?  Are they 100, 3, 7, 10 in your example?  If yes, then number(4) is invalid since you only got 4 items but you are going to get the fifth item from the collection.  In addition, in your "if" statement, you are comparing the value "i" to the first item in your collection, i.e. 100.  I would suggest you first write down your program flow as pseudocode.  Once you got a logical program flow, then translate that into VB.NET.

    2008年11月2日 15:32