Java Interview Programs
Java Interview Programs
Java Interview Programs
}
System.out.println("Number of alphabets :"+ac);
System.out.println("Number of digits :"+nc);
System.out.println("Number of special characters :"+sct);
}
}
int min=ar[0];//Integer.MAX_VALUE;
min2=ar[0];//Integer.MAX_VALUE;
for( i=1;i<5;i++)
{
if(ar[i]<min)
{
min2=min;
min=ar[i];
}
else if((ar[i]< min2)|| (min==min2))
min2=ar[i];
}
System.out.println("min :"+min);
System.out.println("second min ele :"+min2);
}
int charCount = 0;
int wordCount = 0;
int lineCount = 0;
try
{
//Creating BufferedReader object
lineCount++;
currentLine = reader.readLine();
}
String str,a;
boolean b=false;
//File file = new File("e:/test.txt");
FileReader file = new FileReader("e:/test.txt");
Scanner s=new Scanner(file);
System.out.println("enter string to be searched");
str=sc.next();
while(s.hasNext())
{
if(str.equals(s.next()))
{
System.out.println( str +" is present in file");
b=true;
break;
}
}
if(b==false)
System.out.println( str +" not present in file");
System.out.println(al2);
}
}
//Method 1
Object ar[]=al.toArray();
for(Object r:ar)
System.out.println(r);
//Method 2
Integer arr[]=new Integer[5];
al.toArray(arr);
for(Integer r:arr)
System.out.println(r);
arr[3]=23;
arr[4]=90;
for(Integer r:arr)
System.out.println(r);
al.add(12);
al.add(23);
al.add(22);
al.add(11);
al.add(12);
System.out.println("ArrayList :"+al);
LinkedHashSet<Integer> hs=new LinkedHashSet<Integer>(al);
System.out.println("Set :"+hs);
}
//Program for substring
public class subString {
public static void main(String[] args) {
String s1="welcome";
System.out.println(s1.substring(6));//e
System.out.println(s1.substring(7));//no character returned
System.out.println(s1.substring(7,7));//no character returned
System.out.println(s1.substring(4,4));//no character returned
System.out.println(s1.substring(7,4));//java.lang.StringIndexOutOfBoundsException:
String index out of range: -3
}
}
System.out.println(hm);