Pages

Thursday, March 20, 2025

calculate area of circle in Java

 import java.util.*;


public class JavaBasics {

    // code to calculate area of a circle: area = 3.14 x radius x radius.
    public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    float radius = sc.nextFloat();
    float area = 3.14f*radius*radius;
    System.out.println(area);

}
}

MyLearnings:-
1. input f after 3.14, so 3.14 to avoid any floating errors

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...