karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 13 of 143

Java Program to calculate the area of a triangle using Heron's Formula

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 5K+ Views

Heron’s formula gives the area of a triangle when the length of all three sides are already known.Let’s say we have the following three sides of a triangle −s1 = 15191235.0; s2 = 15191235.0; s3 = 1.01235479;Now, use the Heron’s formulae to find the area −area = (s1+s2+s3)/2.0d; resArea = Math.sqrt(area* (area - s1) * (area - s2) * (area - s3));Examplepublic class Demo {    public static void main(String[] args) {       // sides of a triangle       double s1, s2, s3;       double area, resArea;       // three sides of ...

Read More

Sum of the first N Prime numbers

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

The program to print the sum of the first N prime numbers uses the method to find n prime numbers and then add them to find the sum. This sum is saved to an integer that outputs the sum .The code takes a number checks it for prime, if it is prime then adds it to the sum variable. Till n prime number it does the same and then after that it prints the sum.Example Code#include int isprime(int j) {    int count=0;    for(int i = 2 ; i

Read More

Remove all elements from Java LinkedHashSet

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 423 Views

To remove all the elements from LinkedHashSet in Java, use the clear() method.The following is an example to declare LinkedHashSet and add elements to it −LinkedHashSet hashSet = new LinkedHashSet(); hashSet.add(10); hashSet.add(20); hashSet.add(30); hashSet.add(40); hashSet.add(50); hashSet.add(60);Use the clear() method to remove all elements −hashSet.clear();The following is an example −Exampleimport java.util.LinkedHashSet; public class Demo { public static void main(String[] args) { LinkedHashSet hashSet = new LinkedHashSet(); hashSet.add(10); hashSet.add(20); hashSet.add(30); ...

Read More

Get last entry from NavigableMap in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 234 Views

To display the last entry from NavigableMap in Java, use the lastEntry() method.Let us first create NavigableMap.NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); n.put("C", 868); n.put("D", 988); n.put("E", 686); n.put("F", 888); n.put("G", 999); n.put("H", 444); n.put("I", 555); n.put("J", 666);Get the last entry now.n.lastEntry()The following is an example to get the last entry from NavigableMap.Exampleimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap n = new TreeMap(); n.put("A", 498); n.put("B", 389); ...

Read More

Average of odd numbers till a given odd number?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

The average of odd numbers till a given odd number is a simple concept. You just need to find odd numbers till that number then take their sum and divide by the number.If average of odd number till n is to be found. Then we will find odd numbers from 1 to n add then divide it by the number of odd number.ExampleAverage of odd number till 9 is 5 i.e.1 + 3 + 5 + 7 + 9 = 25 => 25/5 = 5There are two methods for calculating the average of odd number till n which is an ...

Read More

Java Program to generate custom random number -1 or 1

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 285 Views

To generate custom random number 1 or -1, you need to use nextBoolean(). At first take a loop and create a Random object on each iteration −for (int i = 0; i < 5; i++) {    Random rand = new Random(); }Now, use nextBoolean() to generate 1 on TRUE condition, ekse -1 −for (int i = 0; i < 5; i++) {    Random rand = new Random();    if (rand.nextBoolean())       System.out.println(1);    else       System.out.println(-1); }Exampleimport java.util.Random; public class Demo {    public static void main(String[] args) {       for (int ...

Read More

Average of even numbers till a given even number?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

To find the average of even numbers till a given even number, we will add all the even number till the given number and t count the number of even numbers. Then divide the sum by the number of even numbers.ExampleAverage of even numbers till 10 is 6 i.e.2 + 4 + 6 + 8 + 10 = 30 => 30/ 5 = 6There are two methods for calculating the average of even number till n which is an even number.Using LoopsUsing FormulaProgram to find the average of even number till n using loopsTo calculate the average of even numbers ...

Read More

Area of a circle inscribed in a regular hexagon?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

The circle inscribed in a regular hexagon has 6 points touching the six sides of the regular hexagon.To find the area of inscribed circle we need to find the radius first. For the regular hexagon the radius is found using the formula, a(√3)/2.Now area of the circle inscribed is 3πa*a/4SampleSide of hexagon − 4Area = 37.68Example Code#include int main(void) {    int a = 14;    float pie = 3.14;    float area = (float)(3*a*a*pie/4);    printf("The area of circle inscribed in the hexagon of side %d is %f", a, area);    return 0; }OutputThe area of circle inscribed ...

Read More

C++ Program to Construct an Expression Tree for a Postfix Expression

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

An expression tree is basically a binary tree which is used to represent expressions. In expression tree, nodes correspond to the operator and each leaf node corresponds to the operand. This is a C++ program to construct an expression tree for a postfix Expression in inorder, preorder and postorder traversals.AlgorithmBegin    Function r() has a character variable as parameter.       If the characters are + or - or * or / then          Return will be -1       If the characters are from A to Z then          Return will ...

Read More

Area of a Circular Sector?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

A circular sector also known as circle sector / sector of a circle is the portion of the circle that is inscribed by between 2 radii. This area is enclosed between two radii and an arc. To find the area inscribed we need to find the angle that is between the two radii. The total area is equal to 360o of angle. To find the area for an angle we will multiply the area by θ/360. This given the area of section inscrible.Where θ is the angle between the two radii in degree.Area of a sector of a circle = ...

Read More
Showing 121–130 of 1,421 articles
« Prev 1 11 12 13 14 15 143 Next »
Advertisements