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 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;
}
}
}
using System;
namespace My_awesome_program
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Write a sentence, and ill count how many words there are.");
string words = Console.ReadLine();
int antal = wordCounter(words);
Console.WriteLine($"There are {antal} sentences.");
//Close program
Console.ReadKey();
}
static int wordCounter(string words)
{
int antal = (words.Split(' ').Length);
return antal;
}
}
}
Comments
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();
~~~
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
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!
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");
}
}
}
IDK if this will but helpful but hopefully I can get some constructive criticism
that is it without any long coding
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();
}
}
}
I did it but I didnt create another method 😁
Here is code:
Here is outcome:
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.
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.
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();
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 ;
}
}
}
My first try :
using System;
namespace MyApp // Note: actual namespace depends on the project name.
{
internal class Program
{
static void Main(string[] args)
{
wordCount();
Console.WriteLine("--------------------------------------------------");
wordCount();
Console.ReadKey();
}
static void wordCount()
{
Console.WriteLine("Write here your sentence : ");
string sentence = Console.ReadLine();
Console.WriteLine("This sentence is " + sentence.Split(' ').Length + " words long.");
}
}
}
bruh it actually works lets gooooooooooo
using System;
using System.Collections.Generic;
namespace F
{
class Program
{
static void Main(string[] args)
{
//Changing the color
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.Black;
Console.Title = "HAHA xD";
Console.WriteLine("Enter a sentence: ");
string sen = Console.ReadLine();
int sen2 = sen.Split(' ').Length;
Console.WriteLine("Your sentence (" + sen + ") has " + sen2 + " words");
Console.WriteLine("HAHA xD");
Console.WriteLine(":)");
// Wait before closing
Console.ReadKey();
}
}
}
Assigment
methods are cool i have to admit it
methods are cool i have to admit it.
Here is mine:
class program
{
static void Main(string[] args)
{
Console.Title = "My awsome totally cool epic pro gamer awsome man gaming for gamers 2023 (REAL)";
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Please say a sentence: ");
Console.ForegroundColor = ConsoleColor.White;
string thing = Console.ReadLine();
Console.WriteLine("There are " + thing.Split(' ').Length + " words in your sentence");
Console.ReadKey();
}
}
Here is my solution:-
using System;
namespace Words_Counter{
class Program{
static void Main(string[] args){
//Appearance
Console.Title = "Words Counter";
//word counter
Console.WriteLine("Enter a sentence: ");
string sentence = Console.ReadLine();
int wordcount = CountWord(sentence);
Console.WriteLine("There are " + wordcount + " words in that sentence.");
// Wait before closing
Console.ReadKey();
}
static int CountWord (string sentence) {
int wordcount = sentence.Split(' ').Length;
return wordcount;
}
}
}
This is my solution::