C#中在控制台应用中能圆满运行的程序不能在窗体应用程序中完美运行,求解
C#中在控制台应用中能完美运行的程序不能在窗体应用程序中完美运行,求解!
控制台程序:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个上限值:(小于" + long.MaxValue.ToString() + ")");
long MAX = Convert.ToInt64(Console.ReadLine());
long[] SXH = Find(MAX);
foreach (long i in SXH)
{
Console.Write(i+",");
}
Console.Write("……");
Console.ReadKey();
}
public static long[] Find(long Max)
{
long[] array1 = new long[Max];
long index=0;
for (long i = 100; i < Max; i++)
{
long[] array2 = divide(i);
long sum = 0;
for (long j = 0; j < array2.Length; j++)
{
sum += Convert.ToInt64(Math.Pow(array2[j], WeiShu(i)));
}
if (sum == i)
{
array1[index] = sum;
index++;
}
}
long[] array3 = new long[index];
for (long i = 0; i < index; i++)
{
array3[i] = array1[i];
}
return array3;
}
private static long[] divide(long sum)
{
long[] array1 = new long[7];
long index = 0;
while (sum != 0)
{
array1[index] = sum % 10;
sum /= 10;
index++;
}
long[] array2 = new long[index];
for (long i = 0; i < index; i++)
{
array2[i] = array1[i];
}
return array2;
}
private static long WeiShu(long sum)
{
long i = 0;
while (sum != 0)
{
i++;
sum /= 10;
}
return i;
}
}
}
------解决思路----------------------
哪里结果不对
楼主 可不可举例说明
------解决思路----------------------
同样.
------解决思路----------------------
label2.Text += i + "\n";
------解决思路----------------------
应该是追加赋值,你这么搞,只能看到最后一次赋值
------解决思路----------------------
label2大小设置成自适应,否则换行后的内容你看不到了
或者改用richtextbox输出结果
控制台程序:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个上限值:(小于" + long.MaxValue.ToString() + ")");
long MAX = Convert.ToInt64(Console.ReadLine());
long[] SXH = Find(MAX);
foreach (long i in SXH)
{
Console.Write(i+",");
}
Console.Write("……");
Console.ReadKey();
}
public static long[] Find(long Max)
{
long[] array1 = new long[Max];
long index=0;
for (long i = 100; i < Max; i++)
{
long[] array2 = divide(i);
long sum = 0;
for (long j = 0; j < array2.Length; j++)
{
sum += Convert.ToInt64(Math.Pow(array2[j], WeiShu(i)));
}
if (sum == i)
{
array1[index] = sum;
index++;
}
}
long[] array3 = new long[index];
for (long i = 0; i < index; i++)
{
array3[i] = array1[i];
}
return array3;
}
private static long[] divide(long sum)
{
long[] array1 = new long[7];
long index = 0;
while (sum != 0)
{
array1[index] = sum % 10;
sum /= 10;
index++;
}
long[] array2 = new long[index];
for (long i = 0; i < index; i++)
{
array2[i] = array1[i];
}
return array2;
}
private static long WeiShu(long sum)
{
long i = 0;
while (sum != 0)
{
i++;
sum /= 10;
}
return i;
}
}
}
------解决思路----------------------
哪里结果不对
楼主 可不可举例说明
------解决思路----------------------
同样.
------解决思路----------------------
label2.Text += i + "\n";
------解决思路----------------------
应该是追加赋值,你这么搞,只能看到最后一次赋值
------解决思路----------------------
label2大小设置成自适应,否则换行后的内容你看不到了
或者改用richtextbox输出结果