Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

BRACKEYS - Solution to C# Tutorial 06 Challenge

2»

Comments

  • AkshayAkshay Member
    edited May 2021

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;


    namespace classes

    {

      class Program

      {

        static void Main(string[] args)

        {

          meetAliens();

          //matte

          Console.ReadKey();

        }

        static void meetAliens()

        {

          Console.WriteLine("write down an sentence");

          string example = Convert.ToString(Console.ReadLine());

          Console.WriteLine("Tottal number of words are "+ example.Split(' ').Length);


           

        }

      }


  • ~~~

          string example = "sussy baka";



          //splits the string every time a custom char is found (define in parenth)

          int wordCount = example.Split(' ').Length;



          Console.WriteLine("Your sentence has: " + wordCount + " words in it.");


          // Wait before closing

          Console.WriteLine("\n\n\n");

          Console.WriteLine("Press any key to close.");

          Console.ReadKey();

    ~~~

  • edited June 2021

    This is my homework :)

    I made some changes and combinations with previous members. Even as my code does not work perfectly I am happy with it right now :)

    ---------------------------------------------

    using System;

    using System.Collections.Generic;


    namespace ConsoleApp1

    {

      class Program

      {

        static void Main(string[] args)

        {

          char input;

          do

          {

            Console.WriteLine("Enter a sentence: ");

            CountWords();

            Console.WriteLine("\nDo you want to try again?");

            Console.WriteLine("Press Y or N");

            input = Convert.ToChar(Console.ReadLine());

          } while (input != 'N');


          Console.WriteLine("Thank you for testing out my code :)\nPress any key to exit.");


          Console.ReadKey();

         }


        static void CountWords()

        {

          string word = Console.ReadLine();

          int numberOfWords = word.Split(' ').Length;

          int letters = word.Length;


           if (numberOfWords == 0)

          {

            Console.WriteLine("Please write a sentance!");


          }

          else if (numberOfWords == 1)

          {

            Console.WriteLine("There is " + numberOfWords + " word in sentence and " + letters + " letters.");

          } 

          

          else if (numberOfWords >= 2)

          {

            Console.WriteLine("There is " + numberOfWords + " words in sentence and " + letters + " letters.");

          }

        }

      }

    }

  • This is my solution

  • marimari Member

    using System;

    using System.Collections.Generic;


    namespace my_awful_program

    {

        class Program

        {

            static void Main(string[] args)

            {

                // Console mod

                Console.Title = "Skynet";

                Console.ForegroundColor = ConsoleColor.Green;

                Console.WindowHeight = 40;



                Console.WriteLine("Put in your phrase ");

                string str = Console.ReadLine();

                Console.Write("Your phrase is " + StrLenght(str) + " words long");



                Console.ReadKey();

            }



            static int StrLenght (string str){


                    int lenght = str.Split(' ').Length;

                    return lenght;


            }

        }

    }

  • Here is mine!i realized that you don't have to use mehods beacuse you can do it faster!

  • using System;
    
    
    namespace VS_CODE
    {
        class Program
        {
            static void Main(string[] args)
            {
                
                Console.WriteLine("Write a sentence.");
    
    
                int wordNum = WordCount(Console.ReadLine());
    
    
                if(wordNum == 1)
                {
                    Console.WriteLine("This sentence has " + wordNum + " word!");
                }else{
                
                    Console.WriteLine("This sentence has " + wordNum + " words!");
                }
    
    
                Console.ReadKey();
    
    
            }
    
    
            static int WordCount (string sentence)
            {
                int wordNum = sentence.Split(' ').Length;
                return wordNum;
            }
        }
    }
    
  • TurtleDevTurtleDev Member
    edited July 2021

    namespace My_Wholesome_Program

    {

        class Program

        {

            

            static void Main(string[] args)

            { 

                Console.WriteLine("Type a sentence: ");

                string words = Console.ReadLine();  

                Console.WriteLine("Your sentence has " + words.Split(' ').Length + " words.");

                Console.ReadKey();

            }

        }

    }


    Here's mine, didn't use any method to do it faster and cleaner. Why homework is fun when Brackeys puts it?

  • using System;

    using System.Collections.Generic;


    namespace c__test_projects

    {

        class Program

        {

            static void Main(string[] args)

            { //create a method that counts the number of words in a sentences

                

                Console.WriteLine("enter a sentence: \n");

                countingwords();


               // wait before closing 

             Console.ReadKey();

            }

            static void countingwords ()

            {

                

                string sentence;

                sentence = Console.ReadLine();

                Console.WriteLine("there's "+ sentence.Split(' ').Length + " words in this sentence");

                


            }

        }

    }

  • using System;
    using System.Collections.Generic;
    
    
    namespace Program
    {
        class Program
        {
    
    
            static void Main(string[] args)
            {
                #region  stuff
                Console.Title = "Window";
                Console.ForegroundColor = ConsoleColor.Green;
                #endregion
    
    
                #region Methods
                CountWords();
                Console.ReadKey(); // wait for input before closing
                #endregion
            }
            static void CountWords()
            {
                Console.WriteLine("input a few words");
                string sentence = Console.ReadLine();
    
    
                int length = sentence.Split(' ').Length;
    
    
                Console.WriteLine("the sentence has " + length + " words");
            }
        }
    }
    
  • IDK if this will but helpful but hopefully I can get some constructive criticism

  • yaser1999yaser1999 Member
    edited September 2021


    that is it without any long coding

  • saisai Member

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;


    namespace ConsoleApp1

    {

      class Program

      {

        static void Main(string[] args)

        {

          string[] students = new string[4];


          Console.WriteLine("Type in Students name: ");



             students[0] = Console.ReadLine();

             students[1] = Console.ReadLine();

          students[2] = Console.ReadLine();

          students[3] = Console.ReadLine();


          Console.WriteLine("\n*********************");


          Array.Sort(students);


            for (int i = 0; 1 < students.Length; i++)

          {

            Console.WriteLine(students[i]);

          }


          Console.ReadLine();

        }

      }

    }

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    
    
    namespace MyApp // Note: actual namespace depends on the project name.
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                Console.WriteLine("Please enter a sentence: ");
                string sentence = Console.ReadLine();
                int words = CountWords(sentence);
    
    
                if (words == 0)
                {
                    Console.WriteLine("\nThere are no words in your sentence.");
                } else if (words == 1)
                {
                    Console.WriteLine("\nThere is 1 word in your sentence.");
                } else
                {
                    Console.WriteLine("\nThere are " + words + " words in your sentence.");
                }
    
    
                // Wait for input before closing
                Console.ReadKey();
            }
    
    
            static int CountWords(string sentence)
            {
                int words = sentence.Split().Length;
                return words;
            }
        }
    }
    
  • using System;
    
    
    namespace Project1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Write a sentence: ");
    
    
                string answer = Console.ReadLine();
    
    
                int acAnswer = answer.Split(' ').Length;
    
    
                Console.WriteLine("There are " + acAnswer + " words in your sentence");
            }
    
    
        }
    }
    

    I did it but I didnt create another method 😁

  • Here is code:


    Here is outcome:


  • ArenAren Member

    I was completely lost during this challenge so I had to look over the solution but I added some code that requires actual text to be written.


    using System;
    
    
    namespace FirstProject
    
    
    {
        class Program
        
        {
    
    
            static void Main(string[] args)
    
    
            {
                int testSentence = 0;
                while (testSentence == 0)
                {
                    Console.WriteLine("Please enter a sentence down below.");
    
    
                    string sentence = Console.ReadLine();
    
    
                    if (sentence == "" || sentence == " ")
                    {
                        Console.WriteLine("Error: You cannot enter an empty sentence.");
                    }
                    else
                    {
                        int numWords = WordsCount(sentence);
    
    
                        Console.WriteLine($"There are {numWords} words in this sentence !");
                        testSentence++;
                    }
                }
    
    
                Console.ReadKey();
            }
    
    
            static int WordsCount (string sentence)
    
    
            {
                int numWords = sentence.Split(' ').Length;
    
    
                return numWords;
    
    
            }
    
    
    
        }
    
    
    }
    
  • chicagolwchicagolw Member

    That was really amazing! For more law and other important cetagories of post visit Chicago Law School. Also we provide free courses that may help you to shine in life. To learn somthing new visit programming hero course free download also we have cyber 71 course free download. For more courses visit us daily.

  • PandoPando Member

    Console.WriteLine("Enter a sentence: ");


    string sentence = Console.ReadLine();

    int wordCount = CountWords(sentence);


    if (wordCount <= 1) {

        Console.WriteLine("There is " + wordCount + " word in your sentence");

    } else {

        Console.WriteLine("There are " + wordCount + " words in your sentence");

    }


    static int CountWords(string sentence)

    {

        int wordCount = sentence.Split(' ').Length;

        return wordCount;

    }



    // Wait before closing

    Console.ReadKey();

  • akritiakriti Member

    Thank you for sharing this kind of great item with us. I am very appreciative of your work.

    Bangalore Escorts

  • using System;


    namespace MyApp // Note: actual namespace depends on the project name.

    {

        internal class Program

        {

            static void Main(string[] args)

            {

             

             Console.WriteLine("Enter your sentence:");

             string sentence = Console.ReadLine();

             int count = counter(sentence);

           

            Console.WriteLine("There are "+count+" words in your setence");

            //wait before close the programm

            Console.ReadKey();


            }


            static int counter (string sentence)

            {

            int count = sentence.Split(' ').Length;

            return count ;

            }

        }

    }

Sign In or Register to comment.