我正在用C#创建一个应用程序.它的作用是评估给定是否为素数以及相同的交换数是否为素数.
当我在Visual Studio中构建我的解决方案时,它说"非静态字段,方法或属性需要对象引用......".我对"volteado"和"siprimo"方法有这个问题.
问题在哪里,我该如何解决?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Write a number: ");
long a= Convert.ToInt64(Console.ReadLine()); // a is the number given by the user
long av = volteado(a); // av is "a" but swapped
if (siprimo(a) == false && siprimo(av) == false)
Console.WriteLine("Both original and swapped numbers are prime.");
else
Console.WriteLine("One of the numbers isnt prime.");
Console.ReadLine();
}
private bool siprimo(long a)
{
// Evaluate if the received number is prime
bool sp …Run Code Online (Sandbox Code Playgroud) 我必须在C#上编写一个方法,将某个键(来自键盘)与特定按钮相关联.例如,如果我按下A,我在表单应用程序上创建的按钮应该显示为正在按下它.
我想在字符串数组的每个位置存储字符串值的每个字符.
我写了这段代码,但Visual Studio说"不能隐式地将类型String转换为String []".
你能告诉我如何解决这个问题吗?
string [] array = Console.ReadLine();
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,"酷"数字是一个正方形和一个立方体的数字,例如:64 = 8 ^ 2和64 = 4 ^ 3.我的应用程序应该在用户给出的范围之间找到"酷数"的数量.我写了我的代码,应用程序运行正常,但它给了我错误的答案.你能来帮我吗?例如:
INPUT
1 100
OUTPUT
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double a = Convert.ToDouble(Console.ReadLine()); // first number in the range
double b = Convert.ToDouble(Console.ReadLine()); // second number in the range
long x = 0;
for (double i = a; i <= b; i++)
{
double cube = 1.0 / 3.0;
double cuad = 1.0 / 2.0;
double …Run Code Online (Sandbox Code Playgroud)