Friday, March 23, 2018

Write a Java Program to take an String array like this String[] s={"Welcome","to","2018","hi","17"} and filter only numbers.


Write a Java Program to take an String array like this String[] s={"Welcome","to","2018","hi","17"} and filter only numbers.



class FilterNumber
{
public static void main(String[] args)
{
String[] s={"Welcome","to","2018","hi","17"};
for(String n:s)
{
try
{
System.out.println(Integer.parseInt(n));
}
catch (NumberFormatException e)
{}
}
}
}



Write a Java Program to take an String array like this String[] s={"Welcome","to","2018","hi","17"} and filter only numbers.
Write a Java Program to take an String array like this String[] s={"Welcome","to","2018","hi","17"} and filter only numbers. [All Java Interview programs]


Write a Java program to take an string array and find the duplicate and sort in ascending order.


Write a Java program to take an string array and find the duplicate and sort in ascending order.



import java.util.*;
class RemoveDuplicateStringArray
{
public static void main(String[] args)
{
String[] s={"z","a","c","a","d","c","b"};
TreeSet<String> ts=new TreeSet<>(Arrays.asList(s));
System.out.println(ts);
}
}





Write a Java program to take an string array and find the duplicate and sort in ascending order.
Write a Java program to take an string array and find the duplicate and sort in ascending order. [All Java Interview Programs]


Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or not.


Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or not.

Given String : google
Input String : gle
Output : gle is the substring of google




import java.util.Scanner;
class Test
{
public static void main(String[] args)
{
String s="google";
Scanner sc=new Scanner(System.in);
System.out.println("Enter an String : ");
String a=sc.next();
boolean flag=false;int len=0;
for(int i=1;i<=s.length()-a.length();i++)
{
for(int j=0;j<a.length();j++)
{
if(a.charAt(j)!=s.charAt(i+j) )
{
len=0;
break;
}
else
len++;
}
if(len==a.length())
{
flag=true;
break;
}
}
if(flag==true)
System.out.println(a+" is the substring of "+s);
else
System.out.println(a+" is not substring of "+s);
}
}





 Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or not.
Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or not. [All Java Interview Programs]






Tuesday, March 20, 2018

Write a program in java to find the longest palindrome from the given String. If the length is same then print in descending order.


Write a program in java to find the longest palindrome from the given String.
If the length is same then print in descending order.

Input : madamLeveLrotornitin
Total Palindromes = madam  ada  LeveL  eve  rotor  oto  nitin  iti
Longest Palindrome : rotor



class Palindrome4
{

public static void main(String[] args) {

// String s="madamLeveLnitin";
// String s="madamnitin";
String s="madamLeveLrotornitin";
String s2="";String s3="";
System.out.print("Total Palindromes =  ");
for(int i=0;i<s.length();i++)
{
for(int j=i+2;j<=s.length();j++)
{
s2=s.substring(i,j);
StringBuffer sb=new StringBuffer(s2).reverse();
if(s2.equals(sb.toString()))
{
System.out.print(s2+"  ");
if(s2.length()>s3.length())
s3=s2;
else if(s2.length()==s3.length())
{
if(s3.compareTo(s2)<0)
s3=s2;
}
}
}
}
System.out.println("\n\nLongest Palindrome = "+s3);
}
}



Write a program in java to find the longest palindrome from the given String.  If the length is same then print in descending order.
Write a program in java to find the longest palindrome from the given String. [All Java Interview Programs]



Write a program in java to print total palindrome strings presented in given string. Input : abcacbbbca Output : [bb, acbbbca, bbb, cac, cbbbc, bcacb]


Write a program in java to print total palindrome strings presented in given string.

Input : abcacbbbca
Output : [bb, acbbbca, bbb, cac, cbbbc, bcacb]


import java.util.*;
class Palindrome3
{
public static void main(String[] args)
{
String s="abcacbbbca";
String s2="";
HashSet<String> hs=new HashSet<>();
for(int i=0;i<s.length();i++)
{
for(int j=i+2;j<=s.length();j++)
{
s2=s.substring(i,j);
StringBuffer sb=new StringBuffer(s2).reverse();
if(s2.equals(sb.toString()))
hs.add(s2);
}
}
System.out.print("Total Palindromes =  "+hs);
}
}



Write a program in java to print total palindrome strings presented in given string.    Input : abcacbbbca  Output : [bb, acbbbca, bbb, cac, cbbbc, bcacb]
Write a program in java to print total palindrome strings presented in given string. [All Java Interview Programs]

Write a program in java to check whether an string is palindrome or not without using reverse method


Write a program in java to check whether an string is palindrome or not
without using reverse method.



public class Palindrome2
{
public static void main(String[] args)
{
String s="malayalam";
String s2="";
for(int i=s.length()-1;i>=0;i--)
s2=s2+s.charAt(i);
if(s.equals(s2))
System.out.println(s+" is palindrome");
else
System.out.println(s+" is not palindrome");
}
}





Write a program in java to check whether an string is palindrome or not without using reverse method
Write a program in java to check whether an string is palindrome or not without using reverse method [All Java Interview Programs]


Write a program in java to check whether an string is palindrome or not

/*
Write a program in java to check whether an string is palindrome or not
*/



public class Palindrome
{
public static void main(String[] args)
{
String s="madam";
String s2=new StringBuffer(s).reverse().toString();
if(s.equals(s2))
System.out.println(s+" is palindrome");
else
System.out.println(s+" is not palindrome");
}
}




Write a program in java to check whether an string is palindrome or not
Write a program in java to check whether an string is palindrome or not [All Java Interview Programs]

Sunday, March 18, 2018

Write a java program to print this numeric pattern 1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13


Write a java program to print this numeric pattern

1  2  3  4
8  7  6  5
9 10 11 12
16 15 14 13



class NumericPattern2
{
public static void main(String[] alt){
int n=4;
for(int i=0;i<n;i++){
for(int j=1;j<=n;j++){
if(i%2==0)
System.out.print(i*n+j+"  ");
else
System.out.print((i+1)*n-j+1+"  ");
}
System.out.println();
}
}
}




Write a java program to print this numeric pattern     1  2  3  4   8  7  6  5   9 10 11 12   16 15 14 13
Write a java program to print this numeric pattern [All Java Interview Programs]

Write a java program to print this numeric pattern 1 2 3 4 8 7 6 5 9 10 11 12 16 15 14 13


Write a java program to print this numeric pattern

1  2  3  4
8  7  6  5
9 10 11 12
16 15 14 13



public class NumericPattern
{
public static void main(String[] args)throws Exception {
int c=0;
for(int i=1;i<=4;i++)
{
if(i%2==1)
{
for(int j=1;j<=4;j++)
System.out.print("   "+ ++c);
c=c+4;
}
else
{
int t=c;
for(int k=1;k<=4;k++)
{
System.out.print("   "+t--);
}
}
System.out.println();
}
}
}




Write a java program to print this numeric pattern     1  2  3  4   8  7  6  5   9 10 11 12   16 15 14 13
Write a java program to print this numeric pattern. [All Java Interview Programs]

Java Program to view System Properties

// Java Program to view System Properties


class SystemProperties
{
public static void main(String[] alt)
{
System.out.println("\nOS Version = "+System.getProperty("os.version"));
System.out.println("\nOS Name = "+System.getProperty("os.name"));
System.out.println("\nOS Architecture = "+System.getProperty("os.arch"));
System.out.println("\nJava Compiler = "+System.getProperty("java.compiler"));
System.out.println("\nExtension Directory = "+System.getProperty("java.ext.dirs"));
System.out.println("\nPath Environment Variable = "+System.getProperty("java.library.path"));
System.out.println("\nFile Separator = "+System.getProperty("file.separator"));
System.out.println("\nPath Separator = "+System.getProperty("path.separator"));
System.out.println("\nCurrent working directory = "+System.getProperty("user.dir"));
System.out.println("\nCurrent working directory = "+System.getProperty("user.dir"));
System.out.println("\nAccount Name = "+System.getProperty("user.name"));
System.out.println("\nJVM implementation version = "+System.getProperty("java.vm.version"));
System.out.println("\nJVM implementation Name = "+System.getProperty("java.vm.name"));
System.out.println("\nJava installation directory = "+System.getProperty("java.home"));
System.out.println("\nJVM version = "+System.getProperty("java.runtime.version"));
System.out.println("\nJVM version = "+System.getProperty("deployment.javaws.jre.0.osname"));
System.out.println("\nJVM version = "+System.getProperty("deployment.javaws.jre.0.path"));
}
}