Programming Articles - Page 2448 of 3366

Python Program for the focal length of a spherical mirror

Pavitra
Updated on 11-Sep-2019 11:51:14

436 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementWe will be given the radius of curvature of the spherical mirror and we have to find the focal length of the same.The focal length is the distance between the centre of curvature of the mirror to the principal foci. In order to determine the focal length of a spherical mirror firstly, we should know the radius of curvature of that mirror. The distance from the vertex of the mirror to the centre of curvature is called the radius of curvature.Mathematically −For concave mirror: ... Read More

Python Program for Finding the vertex, focus and directrix of a parabola

Pavitra
Updated on 11-Sep-2019 11:48:11

1K+ Views

In this article, we will learn about the solution to the problem statement given below −Problem statementThe standard form of a parabola equation is y=ax^2+bx+c. Input the values of a, b and c, our task is to find the coordinates of the vertex, focus and the equation of the directrix.The vertex of a parabola is the coordinate from which it takes the sharpest turn whereas y=a is the straight-line used to generate the curve.A directrix a fixed-line used in describing a curve or surface.Now let’s see the implementation −Example Live Demodef findparabola(a, b, c):    print ("Vertex: (" , (-b / ... Read More

Python Program for Find the perimeter of a cylinder

Pavitra
Updated on 11-Sep-2019 11:45:20

141 Views

In this article, we will learn about the solution to the problem statement given below −Problem statement − Input diameter and height, find the perimeter of a cylinderPerimeter is nothing but the side view of a cylinder i.e. a rectangleTherefore Perimeter= 2 * ( h + d )here d is the diameter of the cylinderh is the height of the cylinderNow let’s see the implementationExample Live Demo# Function to calculate the perimeter of a cylinder def perimeter( diameter, height ) :    return 2 * ( diameter + height ) # main diameter = 5 ; height = 10 ; print ... Read More

How to display a JRadioButtonMenuItem in Java?

raja
Updated on 03-Jul-2020 12:47:44

1K+ Views

A JRadioButtonMenuItem is a subclass of the JMenuItem class in Java. A JRadioButtonMenuItem is a menu item that is part of a group of menu items in which only one item in the group can be selected and the selected item displays its selected state. We can add multiple radio button menu items to a ButtonGroup object to form a button group. If one radio button menu item in a button group is selected, all other radio button menu items will be unselected.Syntaxpublic class JRadioButtonMenuItem extends JMenuItem implements AccessibleExampleimport javax.swing.*; import java.awt.*; public class JRadioButtonMenuItemTest extends JFrame {    private JMenuBar mb;   ... Read More

How can we use the StringTokenizer class in Java?

raja
Updated on 01-Dec-2023 14:52:22

285 Views

A StringTokenizer is a subclass of Object class and it can allow an application to break a string into tokens. A set of delimiters can be specified either at creation time or on a per-token basis. An instance of StringTokenizer behaves in two ways depending on whether it was created with the returnDelims flag having the value true or false. The object of StringTokenizer internally maintains a current position within the string to be tokenized. The important methods of StringTokenizer c;ass are hasMoreElements(), hasMoreTokens(), nextElement(), nextToken() and countTokens(). Syntax public class StringTokenizer extends Object implements Enumeration Example 1 import java.util.*; public class StringTokenizerTest1 { ... Read More

How can we initialize a boolean array in Java?

Vivek Verma
Updated on 05-May-2025 13:46:37

25K+ Views

Initializing a Boolean Array in Java refers to the process of assigning values (allocating memory) to the Boolean array for the first time. We can initialize an array or any variable - Either at the time of creation. Or, later in the program, using the assignment operator when we are just defining it initially. A Boolean array can be used to store only Boolean values (i.e., either true or false), and the "default value" of each element in a Boolean array is false.  In some cases, we may need to initialize all ... Read More

When can we use the pack() method in Java?

raja
Updated on 03-Jul-2020 12:33:28

5K+ Views

The pack() method is defined in Window class in Java and it sizes the frame so that all its contents are at or above their preferred sizes. An alternative to the pack() method is to establish a frame size explicitly by calling the setSize() or setBounds() methods. In general, using the pack() method is preferable to call than setSize() method, since pack leaves the frame layout manager in charge of the frame size and layout managers are good at adjusting to platform dependencies and other factors that affect the component size.Syntaxpublic void pack()Exampleimport java.awt.*; import javax.swing.*; public class PackMethodTest extends JFrame {    public ... Read More

How to read data from PDF file and display on console in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:44:22

11K+ Views

There are several libraries to read data from a pdf using Java. Let us see how to read data from a PDF document and display it on the console using a library named PDFBox.You can extract text using the getText() method of the PDFTextStripper class. This class extracts all the text from the given PDF document to use this.Load an existing PDF document using the static method load() of the PDDocument class.Instantiate the PDFTextStripper class.Retrieve.read the contents of the PDF page to a String using the getText() method of the PDFTextStripper class.Finally, close the document using the close() method of ... Read More

How to calculate String Buffer capacity in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:38:26

1K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More

How can we replace specific part of String and StringBuffer in Java?

Maruthi Krishna
Updated on 10-Sep-2019 13:33:41

311 Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class.Example Live Demopublic class StringExample {    public static void main(String[] args) {       String str = new String("Hello how are you");       System.out.println("Contents of the String: "+str);    } }OutputHello how are youStrings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the ... Read More

Advertisements