Java program to find greatest number in array:
package arraydemo;
public class ArrayDemo {
public static void main(String[] args) {
...
Tuesday, December 29, 2015
Monday, December 28, 2015
Sunday, December 27, 2015
Saturday, December 26, 2015
Friday, December 25, 2015
delete() and deleteCharAt() method
delete() and deleteCharAt() method:
Java provides us to StringBuffer the ability to delete character using the method delete() and deleteCharAt(). These method are shown here:
StringBuffer delete(int startIndex,int endIndex)
StringBuffer deleteCharAt(int...
Fibonacci Using Recusion method
Fibonacci Using Recusion method:
package diamond;
import static diamond.Fibonacci.fibonacciRecusion;
public class FibonacciDemo {
public static void main(String[] args) {
System.out.println("\nFibonacci by recusion");
int febCount=15;
for(int...
Thursday, December 24, 2015
replace() method
Modifying a String:
replace();
The replace method is used to replace the one character of string.It has the general form:
String replace(char original,char replace);
Here is a small program to show how replace() method works:
package stringdemo;
public class ReplaceDemo {
...
equals() Versus ==
equals() Versus ==
We should be clear that equals() method and == operator perform two different operations.The equals() method compares the character inside a string whereas == operator compares two object reference to see whether they refer to the same instances.Here is a small program to demonstrate the difference between...
equals() and equalsIgnoreCase()
String Comparision:
The String class includes many methods that compares Strings or Substrings within strings.
equals() and equalsIgnoreCase()
package stringdemo;
public class StringComparision {
public static void main(String[] args) {
String str="john";
...
Character Extraction
Character Extraction:
2)getChars()
If you want to extract more than one character at a time,you can use the getChars() method.
It has general form:
void getChars(int sourceStart,int sourceEnd,char target[],int targetStart);
package stringdemo;
public class NewClass {
public static void main(String[] args)...
Character Extraction
Character Extraction:
1) charAt()
charAt() method is used to extract single character from String.Here is a small program to demonstrate chatAt() method.
package stringdemo;
public class NewClass {
public static void main(String[] args) {
String ch="java";
...
String Length in java
String Length in java:
The length of the String is the actual number of character that contains in it.To get this value,call the length() method as shown below:
int length();
Here is a short program to demonstrate String length:
package stringdemo;
public class StringLengthDemo {
public static void main(String[]...
The String Constructor:
The String Constructor:
//Construct one String from other
class MakeString{
public Static void main(String[] args){
Char c[]={'d','o','g'};
String s1=new String(c);
String s2= new String(s1);
System.out.println(s1);
System.out.println(s2);
}
}
The output of this program is as follow:
dog
...
Wednesday, December 23, 2015
Tuesday, December 22, 2015
Monday, December 21, 2015
Java Program to show diamond Pattern:
Java Program to show diamond Pattern:
import java.util.Scanner;
public class MyDiamondPattern {
public static void main(String[] args) {
System.out
.print("Enter the number of stars you want in diamond shape: ");
Scanner scan = new Scanner(System.in);
int...
Java program to show Factorail Number:
Java program to show Factorail Number:
import java.util.Scanner;
class MyFactorial {
public static void main(String args[]) {
int n, fact = 1;
System.out.println("Enter an integer to calculate it's factorial");
Scanner in = new Scanner(System.in);
...
Friday, December 18, 2015
Sunday, December 13, 2015
Java program to Demonstrate Abstract Class and Methods
Java program to Demonstrate Abstract Class and Methods:
package abstractclassdemo;
public abstract class Animal {
public abstract void makesound();
}
*******************
package abstractclassdemo;
public class sheep extends Animal {
@Override
public void makesound()...
Saturday, December 12, 2015
java program to find sum of each digit and repeat the process until users exit:
java program to find sum of each digit and repeat the process until users exit:
package javaapplication1;
import java.util.*;
public class SumofeachDigit {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
boolean quite=false;
int choice=0;
do{
...
Thursday, December 10, 2015
Java program to check ArmStrong Number
Java program to check ArmStrong Number:
package javaapplication1;
import java.util.*;
public class ArmStrongNumber {
public static void main(String args[])
{
int n, sum = 0, og, r;
Scanner in = new Scanner(System.in);
System.out.println("Enter...
Wednesday, December 9, 2015
Java program to dispaly a current date:
Java program to dispaly a current date:
package javaapplication1;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class DateDisplay {
public static void main(String args[])
{
int day, month, year;
int second, minute, hour;
...
Tuesday, December 8, 2015
Monday, December 7, 2015
Sunday, December 6, 2015
java program to check whether a number is palindrome or not
java program to check whether a number is palindrome or not:
package javaapplication1;
import java.util.*;
public class PalindromeNumber {
public static void main(String[] args){
int num,rev=0;
int dig;
Scanner in=new Scanner(System.in);
System.out.println("Enter...
Saturday, December 5, 2015
Java program to reverse a number:
Java program to reverse a number:
package javaapplication1;
import java.util.*;
public class ReverseNumber {
public static void main(String args[])
{
int n, reverse = 0;
System.out.println("Enter the number to reverse");
Scanner in = new Scanner(System.in);
...
Java pogram to reverse a string
Java pogram to reverse a string:
package javaapplication1;
import java.util.Scanner;
public class ReverseString {
public static void main(String args[])
{
String orig, rev = "";
Scanner in = new Scanner(System.in);
System.out.println("Enter...