Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

sololearn java shapes coding project

import java.util.Scanner;

abstract class Shape {
    int width;
    abstract void area();
}

public class Square extends Shape{
    
    Square(int w){
        width = w;
    }
    public void area(){
            System.out.println(width * width);
    }
}

public class Circle extends Shape{

    Circle(int w){
        width = w;
    }
    public void area(){
            System.out.println(Math.PI * width*width);
    }
}

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();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java timestamp 
Java :: java ip regex 
Java :: register command spigot 
Java :: spring load config value in variable 
Java :: how to clear a text file in java 
Java :: copy collection java 
Java :: moving text in textview android 
Java :: java yesterday date 
Java :: java get ram usage 
Java :: printwriter java append to file 
Java :: android ancestral navigation 
Java :: flutter request location permission 
Java :: random processing 
Java :: java import decimalformat 
Java :: java flatten list 
Java :: how to print elements in matrix java 
Java :: long to int java 8 
Java :: error:03000086 
Java :: smaller elements on right hand side leetcode 
Java :: java new string array 
Java :: consolenausgabe java 
Java :: java replace whitespace 
Java :: android run background service on startup 
Java :: get last element of array java 
Java :: java swing jtable different color each row 
Java :: traversing 2d array java 
Java :: cors filter spring boot 
Java :: java int to binary string 
Java :: decimal up to 6 places in java 
Java :: java input character 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =