![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
怎么把有按钮界面程序改写为控制台
1、从键盘输入一个正整数,按数字的相反顺序输出。namespaceWindowsFormsApplication21{publicpartialclassForm1:Fo...
1、 从键盘输入一个正整数,按数字的相反顺序输出。
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int a = int.Parse(textBox1.Text);
int b = 0;
while (a > 0)
{
b = b * 10;
b = b + a % 10;
a = a / 10;
}
textBox2.Text = b.ToString();
}
catch
{
MessageBox.Show("输入数字非正整数,请重新输入");
}
}
}
}
这是我改写多次无错误的程序,但运行起来有错误
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public int run (int x,int y)
{
while (x > 0)
{
y = 0;
y = y * 10;
y = y + x % 10;
x = x / 10;
}
return y;
}
static int Main()
{
Program a = new Program();
int x = int.Parse(Console.ReadLine());
int y = 0;
while (x > 0)
{
y = 0;
y = y * 10;
y = y + x % 10;
x = x / 10;
return y;
Console.WriteLine("{0}", y);
}
return x;
}
}
}
那个run方法,本来想在main里调用他,但变量的问题解决不了,干脆放在main,但还是运行不了,那个什么实参 形参...还有ref out...是不是这个y写错? 展开
namespace WindowsFormsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
int a = int.Parse(textBox1.Text);
int b = 0;
while (a > 0)
{
b = b * 10;
b = b + a % 10;
a = a / 10;
}
textBox2.Text = b.ToString();
}
catch
{
MessageBox.Show("输入数字非正整数,请重新输入");
}
}
}
}
这是我改写多次无错误的程序,但运行起来有错误
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public int run (int x,int y)
{
while (x > 0)
{
y = 0;
y = y * 10;
y = y + x % 10;
x = x / 10;
}
return y;
}
static int Main()
{
Program a = new Program();
int x = int.Parse(Console.ReadLine());
int y = 0;
while (x > 0)
{
y = 0;
y = y * 10;
y = y + x % 10;
x = x / 10;
return y;
Console.WriteLine("{0}", y);
}
return x;
}
}
}
那个run方法,本来想在main里调用他,但变量的问题解决不了,干脆放在main,但还是运行不了,那个什么实参 形参...还有ref out...是不是这个y写错? 展开
展开全部
你的程序里 输出之前就 return y; 返回了,当然不会有结果了
下面是我的代码:
static void Main()
{
int x = int.Parse(Console.ReadLine());
while (x > 0)
{
Console.Write(x%10);
x /= 10;
}
}
下面是我的代码:
static void Main()
{
int x = int.Parse(Console.ReadLine());
while (x > 0)
{
Console.Write(x%10);
x /= 10;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询