
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

2K+ Views
A ternary operator uses 3 operands and it can be used to replace the if else statement. This can be done to make the code simpler and more compact.The syntax of the ternary operator is given as follows −Expression ? Statement 1 : Statement 2In the above syntax, the expression is a conditional expression that results in true or false. If the value of the expression is true, then statement 1 is executed otherwise statement 2 is executed.A program that demonstrates the ternary operator in Java is given as follows.Example Live Demopublic class Example { public static void main(String[] args) ... Read More

332 Views
In this article, we will learn how to print a diamond shape pattern using nested loops in Java. This helps in understanding loops and conditional structures in Java programming.A nested loop refers to a loop placed within another loop. This structure is often called "loops within loops" because the inner loop runs completely each time the outer loop iterates.Diamond Shape A diamond shape is a symmetrical pattern that consists of two parts: an upper triangle and a mirrored inverted triangle below it. In programming, such patterns are typically printed using nested loops to control spaces and symbols. A diamond ... Read More

23K+ Views
In this article, we will learn to create a basic calculator using Java. With a basic calculator, we can add, subtract, multiply, or divide two numbers. This is done using a switch case. A program that demonstrates this is given as follows − Problem Statement Write a program in Java to create a basic calculator for performing the basic arithmetic operations − Input Enter two numbers: 23Enter an operator (+, -, *, /): + Output The result is given as follows:2.0 + 3.0 = 5.0 Steps to create basic calculator Following are the steps to create a basic calculator program using ... Read More

1K+ Views
The common elements in three sorted arrays are those elements that occur in all three of them. In this article, we will learn how to find common elements from three sorted arrays in Java. An example of this is given as follows − Example Scenario: Input 1: arr1 = [1, 3, 5, 7, 9] Input 2: arr2 = [2, 3, 6, 7, 9] Input 3: arr3 = [1, 2, 3, 4, 5, 6, 7, 8, 9] Output: Common elements = 3 7 9 Here, arrays are data structure which stores a fixed-size sequential collection of elements of the same ... Read More

14K+ Views
The number of times a word occurs in a string denotes its occurrence count. An example of this is given as follows −String = An apple is red in colour. Word = red The word red occurs 1 time in the above string.A program that demonstrates this is given as follows.Example Live Demopublic class Example { public static void main(String args[]) { String string = "Spring is beautiful but so is winter"; String word = "is"; String temp[] = string.split(" "); int count = 0; for (int i = 0; i < temp.length; i++) { if (word.equals(temp[i])) count++; } System.out.println("The string ... Read More

543 Views
Extraction of k bits from the given position in a number involves converting the number into its binary representation. An example of this is given as follows −Number = 20 Binary representation = 10100 k = 3 Position = 2 The bits extracted are 010 which represent 2.A program that demonstrates this is given as follows.Example Live Demopublic class Example { public static void main (String[] args) { int number = 20, k = 3, pos = 2; int exNum = ((1 > (pos - 1)); System.out.println("Extract " + k + ... Read More

2K+ Views
Problem Statement Two matrices are identical if their number of rows and columns are equal and the corresponding elements are also equal. An example of this is given as follows. Input Matrix A = 1 2 3 4 5 6 7 8 9 Matrix B = 1 2 3 4 5 6 7 8 9 The matrices A and B are identical Output Both the matrices are identical Steps to check if two given matrices are identical Following are the steps to check if two given matrices are identical − Initialize two matrices by defining two ... Read More

33K+ Views
We are given a String and our task is to write Java programs that count its words. A string is a class in Java that stores a series of characters enclosed within double quotes. To count words of the given strings, check whether the character at the current index is a whitespace (' ') or a letter. If it is whitespace and the next character is a letter. Then, increment the counter variable to specify we have encountered a word. Example Scenario: Input: "You are on Tutorials Point website"; Output: Number of words in the given string: 6 ... Read More

5K+ Views
Two variables can be swapped in one line in Java. This is done by using the given statement. x = x ^ y ^ (y = x); where x and y are the 2 variables. A program that demonstrates this is given as follows − Example Live Demo public class Example { public static void main (String[] args) { int x = 12, y = 25; System.out.println("Original values of x and y"); System.out.println("x = " ... Read More

806 Views
The total bits in a number can be counted by using its binary representation. An example of this is given as follows − Number = 9 Binary representation = 1001 Total bits = 4 A program that demonstrates this is given as follows. Example Live Demo public class Example { public static void main(String[] arg) { int num = 10; int n = num; int count = 0; while ... Read More