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
Programming Articles - Page 2535 of 3363
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 Live Demo#include int isprime(int j) { int count=0; for(int i = 2 ; i
695 Views
Adding up all natural numbers up to n, that are divisible by X or Y is selecting all the numbers that are divisible by X or Y and adding them to a variable that stores the sum.To find the sum of the first N natural numbers which are divisible by X or Y, there are two methods −Using loops and conditional statementsUsing formulaMethod 1 − Using loops and conditional statementsThis method uses a loop that counts up to n numbers and selects numbers that are divisible by X or Y and adds them and save to a variables at each ... Read More
1K+ Views
A program to add two numbers takes to numbers and does their mathematical sum and gives it to another variable that stores its sum.Example Code Live Demo#include int main(void) { int a = 545; int b = 123; printf("The first number is %d and the second number is %d ", a , b); int sum = a + b; printf("The sum of two numbers is %d" , sum); return 0; }OutputThe first number is 545 and the second number is 123 The sum of two numbers is 668
17K+ Views
The area is a quantity that represents the extent of the figure in two dimensions. The area of a circle is the area covered by the circle in a two dimensional plane.To find the area of a circle, the radius[r] or diameter[d](2* radius) is required.The formula used to calculate the area is (π*r2) or {(π*d2)/4}.Example CodeTo find the area of a circle using radius. Live Demo#include int main(void) { float pie = 3.14; int radius = 6; printf("The radius of the circle is %d " , radius); float area = (float)(pie* radius * radius); printf("The ... Read More
1K+ Views
A program to add 1 to a given number increments the value of the variable by 1 . This is general used in counters.There are 2 methods to increase that can be used to increase a given number by 1 −Simple adding of one to the number and reassigning it to the variable.Using increment operator in the program.Method 1 − using reassignment methodThis method takes the variable, add 1 to it and then reassigns its value.Example Code Live Demo#include int main(void) { int n = 12; printf("The initial value of number n is %d ", n); n ... Read More
1K+ Views
Average or mean of n even natural number is the sum of numbers divided by the numbers.You can calculate this by two methods &minusFind the sum of n even natural numbers and divide it by number, Using loop.Find the sum of n even natural numbers and divide it by number, Using formula.Method 1 - Using LoopFind the sum of even natural numbers using a loop that counts up to the number we want the sum. Then we will divide it by n.Example Code Live Demo#include int main(void) { int n = 5; int sum = 0; int ... Read More
389 Views
The Arrays class of the java.util package provides a method named toString() this method accepts an array value (of any type) and returns a String.ExampleFollowing Java program accepts various arrays from the user, converts them into String values and prints the results. Live Demoimport java.util.Arrays; import java.util.Scanner; public class ObjectArrayToStringArray { public static void main(String args[]){ Scanner sc = new Scanner(System.in); //Integer array to String System.out.println("Enter 5 integer values: "); int intArray[] = new int[5]; for(int i=0; i
1K+ Views
An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.Just like classes you can extend one interface from another using the extends keyword as shown below −interface ArithmeticCalculations{ public abstract int addition(int a, int b); public abstract int subtraction(int a, int b); } interface MathCalculations extends ArithmeticCalculations{ public abstract double squareRoot(int a); public abstract double powerOf(int a, int b); }But, when you implement the sub-class you need to provide body for the abstract methods in both interfaces.ExampleIn the following example we have created two interfaces ... Read More
4K+ Views
In this article, we will learn to implement a JLabel text with different colors and fonts in Java. JLabel is commonly used for simple text display, it can be enhanced to show text with multiple colors and fonts. JLabel A JLabel class can extend the JComponent class, and an object of JLabel provides text instructions or information on a GUI. A JLabel can display a single line of read-only text, an image, or both text and an image. A JLabel can explicitly generate a PropertyChangeListener interface. Different Approaches The following are the two different approaches to implementing a JLabel text ... Read More
541 Views
In this article, we will learn to insert multiple tabs into a single JTabbedPane in Java. The Java Swing's JTabbedPane enables you to group content into several tabs in one container. JTabbedPane A JTabbedPane is a component can extends the JComponent class, and we can able to see only one tab at a time. Each tab is associated with a single component that can be displayed when the tab is selected. Syntax Object declaration and instantiation using the Java class JTabbedPane: JTabbedPane tabbedPane = new JTabbedPane(); A JTabbedPane can generate a ChangeListener interface when a tab is ... Read More