Причина ошибки "A get or set accessor expected" - C#
Формулировка задачи:
using System;
using System.IO;
using System.Text;
using System.Threading;
namespace optimizationMethods {
public class MethodSegmentIntoThree
{
public static readonly double EPS = 0.0001;
public static double f (double x)
{
return (Math.Sqrt(x*x + 25) + Math.Sqrt ((20-x)*(20-x)+100) +0.1);
}
public static double[] setSegment() throws IOException //просит поставить
// точку с запятой перед throws error CS1002: ; expected
{
double[] x = new double[4]; //выдаёт error CS1014: A get or set
// accessor expected
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Console.WriteLine("Введите отрезок [a; b], на котором будем искать стационарную точку");
Console.WriteLine("x1 = ");
x[0] = Double.parseDouble(reader.readLine());
x[1] = 0; x[2] = 0;
Console.WriteLine("x4= ");
x[3] = Double.parseDouble(reader.readLine());
System.out.prinln("Ищем стационарную точку...");
return x;
}
public static double segIntoThree (double[] x)
{
while ( Math.Abs(x[3] - x[0] ) >=EPS )
{
x[1]=x[0]+(x[3]-x[0])/3;
x[2]=x[3]-(x[3]-x[0])/3;
if (f(x[1]) < f(x[2]))
x[3]= x[2];
else
x[0] = x[1];
}
return (x[0] + x[3] ) / 2;
}
public static void main(string[] args)
{
try
{
double[] x = setSegment();
Console.WriteLine("Точка минимума z = " + segIntoThree(x));
Console.WriteLine("f(z) = " +f(segIntoThree(x)));
Console.WriteLine("Значение функции(для проверки): f(z) = f(3) = " +f(6.6667));
}
catch (IOException e)
{
e.printStackTrace();
}
}
} }Решение задачи: «Причина ошибки "A get or set accessor expected"»
textual
Листинг программы
using System;
using System.IO;
using System.Text;
using System.Threading;
namespace optimizationMethods {
public class MethodSegmentIntoThree
{
public static readonly double EPS = 0.0001;
public static double f (double x)
{
return (Math.Sqrt(x*x + 25) + Math.Sqrt ((20-x)*(20-x)+100) +0.1);
}
public static double[] setSegment()
{
double[] x = new double[4];
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//error CS1041: Identifier expected; 'in' is a keyword
// the type of namespace bufferedreader could not be found
// the type of namespace InputStreamReader could not be found
// error CS1525: Invalid expression term 'in
Console.WriteLine("Введите отрезок [a; b], на котором будем искать стационарную точку");
Console.WriteLine("x1 = ");
x[0] = Double.parseDouble(reader.readLine());
x[1] = 0; x[2] = 0;
Console.WriteLine("x4= ");
x[3] = Double.parseDouble(reader.readLine());
System.out.prinln("Ищем стационарную точку...");
return x;
}
public static double segIntoThree (double[] x)
{
while ( Math.Abs(x[3] - x[0] ) >=EPS )
{
x[1]=x[0]+(x[3]-x[0])/3;
x[2]=x[3]-(x[3]-x[0])/3;
if (f(x[1]) < f(x[2]))
x[3]= x[2];
else
x[0] = x[1];
}
return (x[0] + x[3] ) / 2;
}
public static void main(string[] args)
{
try
{
double[] x = setSegment();
Console.WriteLine("Точка минимума z = " + segIntoThree(x));
Console.WriteLine("f(z) = " +f(segIntoThree(x)));
Console.WriteLine("Значение функции(для проверки): f(z) = f(3) = " +f(6.6667));
}
catch (IOException e)
{
e.printStackTrace();
//error CS1061:
//'System.IO.IOException' does not contain a definition for 'printStackTrace' and no extension method 'printStackTrace' //accepting a first argument of type 'System.IO.IOException' could be found (are you missing a using directive or an //assembly reference?)
}
}
} }