Задача 56. Фигуры. Нужно вывести площади фигур. Не проходит 3-ий тест, хотя остальные нормально проходит, может кто помочь? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Задача 56. Фигуры. Нужно вывести площади фигур. Не проходит 3-ий тест, хотя остальные нормально проходит, может кто помочь?

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //введите код сюда public class Square extends Shape{ Square (int x) { width = x; } @Override void area(){ System.out.println(width*width); } } public class Circle extends Shape{ Circle (int y) { width = y; } @Override void area () { System.out.println(width*width*Math.PI); } } // конец кода public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Square a = new Square(x); Circle b = new Circle(y); a.area(); b.area(); } }

16th Feb 2022, 1:51 PM
Дмитрий Нуйков
Дмитрий Нуйков - avatar
3 Antworten
+ 3
Use System.out.println("Math.PI*width*width) ;
16th Feb 2022, 2:03 PM
Jayakrishna 🇮🇳
+ 1
Wow, I don't know why, but it worked, thanks!
16th Feb 2022, 5:11 PM
Дмитрий Нуйков
Дмитрий Нуйков - avatar
+ 1
double * int * int makes difference with int * int * double in the precision data with large values . You're welcome..
16th Feb 2022, 6:56 PM
Jayakrishna 🇮🇳