naveengarg2k5
BAN USERpublic static void occuranceWord(String string, String word){
String original = string;
int count =0;
String[] str2 = original.split(" ");
int l = str2.length;
String str3=null;
for(int i=0; i<l; i++){
if(word.equals(str2[i])){
++count;
}
}
System.out.println(count);
}
import java.util.*;
public class Stock {
public static void inStock(int productId){
int id = productId;
HashMap<Integer,Integer> stock = new HashMap<Integer, Integer>();
stock.put(101,5);
stock.put(102,6);
stock.put(103,7);
stock.put(104,8);
stock.put(105,9);
int value = stock.get(id);
if(value==0){
System.out.println(" stock of the product is null");
}
else if( value>0 && value<25) {
System.out.println(" stock of the product going to finish but above 0 and less than 25");
}
else {
System.out.println(" we have a sufficient");
}
}
public static void main(String args[]){
inStock(102);
}
}
public class Singleton {
private static Singleton singleton =null;
private Singleton(){
}
public static Singleton getInstance(){
if(singleton = =null){
singleton = new Singleton();
}
return singleton;
}
}
hi Hari you are right but i right for general purpose but we also prevent from cloning so will use clone() method
- naveengarg2k5 August 03, 2012protected Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("Cloning of this class is not allowed");
}