Нужна помощь по коду Java. Статические классы, объекты и методы, код не желает запускаться, не знаю в чем причина
import java.util.Scanner;
class MathFun {
static int sthow;
static MathFun() {
}
public static float Mean(float x){
return x;
}
public static float cos(float x){
float y = Math.cos(x);
return y;
}
public static float tg(float x){
float y = Math.tan(x);
return y;
}
public static float ctg(float x){
float y = Math.cos(x)/Math.sin(x);
return y;
}
public static float Sqrt(float x){
float y = Math.sqrt(x);
return y;
}
public static int Round(float x){
int y = Math.round(x);
return y;
}
public static float Upsidedown(float x){
float y = 0-x;
return y;
}
public static float NotInt(float x){
int y = Math.round(x);
float v = x-y;
return v;
}
public static int Int(float x){
int y = Math.round(x);
float v = x-y;
int d = x-v;
return d;
}
public static boolean WhatParity(float a){
if (a%2==0){
return true;
}
else{
return false;
}
}
public static float Factorial(int x){
int f = 1;
for (int i = 1; i <=x; i ++){
f = f*i;
}
return f;
}
public static float NSD(float x, float y){
if (x == 0){
return y;
}
while (y != 0) {
if (x > y){
x = x - y;
}
else{
y = y - x;
}
return x;
}
}
public class Main
{
public static void main(String[] args) {
MathFun v = new MathFun();
Scanner in = new Scanner(System.in);
System.out.println("print x");
float x = in.nextFloat();
System.out.println("print x");
float y = in.nextFloat();
float s = v.Mean(x);
System.out.println("x="+s);
float a = v.cos(x);
System.out.println("cos x="+a);
float q = v.tg(x);
System.out.println("tg x="+q);
float w = v.ctg(x);
System.out.println("ctg x="+w);
float e = v.Sqrt(x);
System.out.println("sqrt x="+e);
int r = v.Round(x);
System.out.println("round x="+r);
float t = v.Upsidedown(x);
System.out.println("not x="+t);
float k = v.NotInt(x);
System.out.println("not int x="+k);
int u = v.Int(x);
System.out.println("int x="+u);
boolean i = v.WhatParity(x);
System.out.println("parity x="+i);
float o = v.Factorial(x);
System.out.println("factorial x="+o);
float p = v.NSD(x, y);
System.out.println("NSD x&y="+p);
}
}
выдает такую ошибку: Main.java:110: error: reached end of file while parsing } ^ 1 error помогите пожалуйста, уже даже не знаю что делать
Ответы (2 шт):
Автор решения: Алексей Шиманский
→ Ссылка
не хватает ещё одной } перед public class Main
либо в методе NSD у else убрать { если он не предполагался
Автор решения: AlekseiGaile
→ Ссылка
public class Main {
public static void main(String[] args) {
MathFun v = new MathFun();
Scanner in = new Scanner(System.in);
System.out.println("print x");
float x = in.nextFloat();
System.out.println("print x");
float y = in.nextFloat();
float s = v.Mean(x);
System.out.println("x=" + s);
double a = v.cos(x);
System.out.println("cos x=" + a);
double q = v.tg(x);
System.out.println("tg x=" + q);
double w = v.ctg(x);
System.out.println("ctg x=" + w);
double e = v.Sqrt(x);
System.out.println("sqrt x=" + e);
int r = v.Round(x);
System.out.println("round x=" + r);
float t = v.Upsidedown(x);
System.out.println("not x=" + t);
float k = v.NotInt(x);
System.out.println("not int x=" + k);
float u = v.Int(x);
System.out.println("int x=" + u);
boolean i = v.WhatParity(x);
System.out.println("parity x=" + i);
int o = (int) v.Factorial((int) x);
System.out.println("factorial x=" + o);
float p = v.NSD(x, y);
System.out.println("NSD x&y=" + p);
}
}
class MathFun {
static int sthow;
MathFun() {
}
public static float Mean(float x) {
return x;
}
public static double cos(float x) {
double y = Math.cos(x);
return y;
}
public static double tg(float x) {
double y = Math.tan(x);
return y;
}
public static double ctg(float x) {
double y = Math.cos(x) / Math.sin(x);
return y;
}
public static double Sqrt(float x) {
double y = Math.sqrt(x);
return y;
}
public static int Round(float x) {
int y = Math.round(x);
return y;
}
public static float Upsidedown(float x) {
float y = 0 - x;
return y;
}
public static float NotInt(float x) {
int y = Math.round(x);
float v = x - y;
return v;
}
public static float Int(float x) {
int y = Math.round(x);
float v = x - y;
float d = x - v;
return d;
}
public static boolean WhatParity(float a) {
if (a % 2 == 0) {
return true;
} else {
return false;
}
}
public static float Factorial(int x) {
int f = 1;
for (int i = 1; i <= x; i++) {
f = f * i;
}
return f;
}
public static float NSD(float x, float y) {
if (x == 0) {
return y;
}
while (y != 0) {
if (x > y) {
x = x - y;
} else {
y = y - x;
}
}
return x;
}
}
Очень много проблем с типами. Сильно не разбирался, но вот так работает.