how to separate numbers by asterisks c# [closed] - c#

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I don't understand how to do this im new to programming but im sure its simple. help the code I have so far is:
I need the asterisks to be separating the numbers
for (int i = 0; i < 101; i++)
Console.WriteLine(i);
Console.WriteLine("********");
but the asterisks is only showing at the bottom

You should put the body of the loop into a scope:
for (int i = 0; i < 101; i++)
{
Console.WriteLine(i);
Console.WriteLine("********");
}
Otherwise only the following next command is interpreted as the body of the loop, equivalent to this:
for (int i = 0; i < 101; i++)
{
Console.WriteLine(i);
}
Console.WriteLine("********");

The way you have it is only doing the for loop on the first line. You need to put both lines into a 'block' using curly braces:
for (int i = 0; i < 101; i++)
{
Console.WriteLine(i);
Console.WriteLine("********");
}

Related

for (var i = 0; i < count; i++) { } == for (var i = 0; i < count; i++) { }. What is this notation and why use it? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Ran into the notation:
for (var i = 0; i < count; i++) { }
on this tutorial. I gather it is equivalent to:
for(var i = 0; i < count; i++) { }
What is this notation? Why use it? Does it perform better?
It's an HTML parsing error. < is supposed to show up as <. You're right - it's supposed to be i < count.

C# - Cannot implicitly convert type `int' to `int[][]' - CodeFights [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
When attempting to use the following bit of code to answer a question Box Blur on the website CodeFights.com, I receive the following message which has me stumped:
file.cs on line 2: error CS0029: Cannot implicitly convert type `int' to `int[][]'
I'm confident that this is something simple that I'm missing but, my searching for an answer to this has not returned any success.
Any ideas as to what simple mistake I am committing?
int[][] boxBlur(int[][] matrix) {
int[][] result = new int[matrix.Length-2][matrix[0].Length-2];
for (int i =1; i < matrix.Length-1; i++)
for (int j = 1; j < matrix[0].Length-1; j++)
{
int sum=0;
for(int k=i-1; k<=i+1; k++)
{
for(int m=j-1;m<=j+1;m++)
{
sum+=matrix[k][m];
}
}
result[i-1][j-1]=sum/9;
}
return result;
}
Wrong call array. Try this(or something like):
int[][] result = new int[matrix.Length - 2][];
for(int i=0; i< matrix.Length - 2; i++)
{
result[i] = new int[matrix[0].Length - 2];
}
int[][] is an array of arrays. You can't initialize the size of the arrays within it when you're initializing it.
If you want a two-dimensional array, use int[,].

Why does for-loop show nothing in cmd [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have problem with for loop in C#.
I have the following code, in main method:
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for(int i=0;i>20;i++)
{
if(i%2==0)
{
Console.WriteLine("{0},", i);
}
}
Console.ReadLine();
}
}
}
The for loop does not execute. Why?
Change condition, > to <:
...
for (int i = 0; i < 20; i++) // i < 20, not i > 20
...
In your original code you assign int i = 0 then check i > 20 get false and do not enter the loop at all
The following statement in your code:
for (int i = 0; i > 20; i++)
First assigns 0 to i then evaluates the condition i > 20 which is wrong, so the for block can not be executed.
Other people have pointed out the fact that the test should actually be "i < 20" rather than "i > 20) but just to make one other point: if all you're trying to do is write out all the even numbers, you can actually increment "i" by 2 every time - that way you never have to test to see if it's even (just write "i += 2" instead of "i++").

Making an array ints and replace the order of number I write [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What I try to do, is for example if I write five numbers 1,2,3,4,5 after this it should print 5,4,3,2,1
int[] numbers = new int[5];
for (int i = 0; i < numbers.Length ; i++)
{
Console.Write("");
numbers[i] = int.Parse(Console.ReadLine());
}
for (int i = 0; i < numbers.Length; i++)
{
}
If you need just to print them in a reverse order, but you want to keep them stored as you inserted them, change the second loop like this:
for (int i=numbers.Length-1; i >= 0; i--){
Console.WriteLine(numbers[i]);
}
You can print the array with a reverse loop as in the previous answer, or you can do that in a single line:
Console.WriteLine(string.Join(",", numbers.Reverse()));

System.IndexOutOfRangeException when checking for being in range [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am checking for the index to be in range, but it's throwing a System.IndexOutOfRangeException... Theoretically the following should work:
for (int b = 1; b <= p.Length-2; a++)
but I still get a
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at scred.Program.Main(String[] args) in c:\Users\\Documents\Visual Studio
2013\Projects\CodeJam\Store Credit - Small (C-Sharp)\Program.cs:line 29
on run
Code: https://gist.github.com/mypalsminecraft/9498980 (who needs Pastebin?)
It seems like that you have done a copy&paste error:
for (int a = 1; a <= p.Length-2; a++)
{
bool done = false;
for (int b = 1; b <= p.Length-2; a++)
{
should be
for (int a = 1; a <= p.Length-2; a++)
{
bool done = false;
for (int b = 1; b <= p.Length-2; b++)
{
instead. Notice the b++ instead of the a++.

Categories

Resources