Array in Java

Java Array In Java Programming,it becomes necessary to store data within the memory in the most convenient and ecnomical way.We may need to structure the memory to stor numerous data items by applying minimum set of variables and by using optimum memory space.This will done with the help of dimensional array.     Array Definition: […] Continue reading →

Even/Odd program in Java

/* Even Odd Number Example */   import java.io.*; public class EvenOdd { public static void main(String[] args) { //create an array of 10 numbers int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10}; for(int i=0; i < numbers.length; i++){ /* * use modulus operator to check if the number is even or odd. * If we divide any […] Continue reading →

Factorial in Java

/* Java Factorial Example */ import java.io.*; class fact { public static void main(String[] args) { int number = 5; /* * Factorial of any number is !n. * For example, factorial of 4 is 4*3*2*1. */ int factorial = number; for(int i =(number – 1); i > 1; i–) { factorial = factorial * […] Continue reading →

Calculate Rectangle Area in Java

/* Calculate Rectangle Area using Java Example */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader;   public class RectArea { public static void main(String[] args) { int width = 0; int length = 0; try { //read the length from console BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println(“Please enter length of a rectangle”); length = Integer.parseInt(br.readLine()); […] Continue reading →

Calculate Circle Perimeter in Java

/* Calculate Circle Perimeter using Java Example */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class CirPeri { public static void main(String[] args) { int radius = 0; System.out.println(“Please enter radius of a circle”); try { //get the radius from console BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); radius = Integer.parseInt(br.readLine()); } //if invalid value was entered […] Continue reading →

Area of a Circle in Java

/*Calculate  Area Of a Circle in Java Example*/ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; class cir{ public static void main(String[] args) { int radius = 0; System.out.println(“Please enter radius of a circle”); try { //get the radius from console BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); radius = Integer.parseInt(br.readLine()); } //if invalid value was entered catch(NumberFormatException […] Continue reading →

Swap number in Java

/* Swap Numbers Java Example*/ import java.io.*; class sw{ public static void main(String[] args) { int num1 = 10; int num2 = 20; System.out.println(“Before Swapping”); System.out.println(“Value of num1 is :” + num1); System.out.println(“Value of num2 is :” +num2); //swap the value swap(num1, num2); } private static void swap(int num1, int num2) { int temp = […] Continue reading →
Page 1 of 44123456»102030...Last »