
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

531 Views
To generate a sum triangle of a given arrayGet the elements of the array from the user say, myArray[n].Create a two dimensional array say, result[n][n].Store the contents of the given array in the first row from bottom of the 2D array.result[n][i] = myArray[i].Now, from the second row of the 2D array fill elements such that ith element in each row is the sum of ith and (i+1)st elements of the previous row.result[i][j] = result[i+1][j] + result[i+1][j+1];Example Live Demoimport java.util.Scanner; public class SumTriangleOfAnArray { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter ... Read More

887 Views
Following is a Java program to find an element in an array linearly.Example Live Demoimport java.util.Scanner; public class SearchingRecursively { public static boolean searchArray(int[] myArray, int element, int size){ if (size == 0){ return false; } if (myArray[size-1] == element){ return true; } return searchArray(myArray, element, size-1); } public static void main(String args[]){ System.out.println("Enter the required size of the array: "); Scanner s = new Scanner(System.in); int size = s.nextInt(); int myArray[] = new int [size]; System.out.println("Enter the elements of the array one by one "); for(int i=0; i

3K+ Views
To rotate the contents of an array cyclically −create an empty variable. (temp)save the last element of the array in it.Now, starting from the nth element of the array, replace the current element with the previous element.Store the element in temp in the 1st position.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class CyclicallyRotateanArray { public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.println("Enter the required size of the array ::"); int size = sc.nextInt(); int [] myArray = new int[size]; System.out.println("Enter elements of ... Read More

20K+ Views
To find the product of elements of an array.create an empty variable. (product)Initialize it with 1.In a loop traverse through each element (or get each element from user) multiply each element to product.Print the product.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class ProductOfArrayOfElements { public static void main(String args[]){ System.out.println("Enter the required size of the array :: "); Scanner s = new Scanner(System.in); int size = s.nextInt(); int myArray[] = new int [size]; int product = 1; System.out.println("Enter the elements of the ... Read More

601 Views
To find the angles of a triangle we can use sin/cosine rules according to cosine rule −cos A = (b^2 + c^2 - a^2)/2bcwhere A, B , C are the vertices and a, b, c are the sides of the given triangle then, angles of the triangle when the sides a, b, c given are −angleAtA = acos((b^2 + c^2 - a^2)/(2bc)) angleAtB = acos((a^2 + c^2 - b^2)/(2ac)) angleAtC = acos((a^2 + b^2 - c^2)/(2ab))

2K+ Views
In this article, we will learn to implement right right-click menu using JPopupMenu in Java. A JPopupMenu appears anywhere on the screen when the right mouse button is clicked. JPopupMenu A JPopupMenu menu is a free-floating menu that is associated with an underlying component called the invoker. Most of the time, a popup menu is linked to a specific component to display context-sensitive choices. Syntax The following is the syntax for JPopupMenu initialization: JPopupMenu popup = new JPopupMenu(); In order to create a popup menu, we can use the JPopupMenu class., We can add the JMenuItem to the ... Read More

2K+ Views
In Java, a JTextPane is an extension of JEditorPane which provides word processing features like fonts, text styles, colors and etc. If we need to do heavy-duty text processing, we can use this class, whereas a JEditorPane supports display/editing of HTML and RTF content and can be extended by creating our own EditorKit. JTextPane A JTextPane is a subclass of JEditorPane. A JTextPane is used for a styled document with embedded images and components. A JTextPane is a text component that can be marked up with the attributes that are represented graphically and it can use a DefaultStyledDocument as the ... Read More

301 Views
The class which process the WindowEvent needs to be implemented this interface and an object of this class can be registered with a component by using addWindowListener() method.Methods of WindowListener InterfaceThe WindowListener interface defines 7 methods for handling window eventsvoid windowActivated(WindowEvent we) − Invoked when a window is activated.void windowDeactivated(WindowEvent we) − Invoked when a window is deactivated.void windowOpened(WindowEvent we) − Invoked when a window is opened.void windowClosed(WindowEvent we) − Invoked when a window is closed.void windowClosing(WindowEvent we) − Invoked when a window is closing.void windowIconified(WindowEvent we) − Invoked when a window minimized.void windowDeiconfied(WindowEvent we) − Invoked when a window is restored.Syntaxpublic ... Read More