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 { ...

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)); ...

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...

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...

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=""; ...

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); ...

Sunday, March 18, 2018

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")); ...

How to make our classes as immutable class by using Java programming?

/* How to make our classes as immutable clas by using Java programming? */ final class Employee { final int id; final String name; public Employee(int id,String name) { this.id=id; this.name=name; } public int getId() { return id; } public String getName() { return name; } } class ImmutableClass { public static void main(String[] alt) { Employee e1=new...

Write a java program in java to reverse each word of string like this input:-"Altaf Java Blog" output:-"Blog Java Altaf"

/* Write a java program in java to reverse each word of string like this input:-"Altaf Java Blog" output:-"Blog Java Altaf" */ class ReverseString3 { public static void main(String[] alt) { String s="Altaf Java Blog"; String[] s2=s.split(" "); String s3=new String(); for(int i=s2.length-1;i>=0;i--) { s3=s3.concat(s2[i]+" "); } System.out.println(s3); ...

WAP in java to reverse each word of string like input : "Sriman java group" output:- "namirS avaJ puorG"

/* WAP in java to reverse each word of string like input : "Sriman java group" output:- "namirS avaJ puorG" Note: Here instead of String we are using StringBuffer because we cannot modify the string object beacause of String immutability. If we use String concat() method then every time new object will be created which is memory causes memory wastage. */ class ReverseString2 { ...

Write a Java progarm to input this and print this Input =a2c3z5 Output = aaccczzzzz

/* Write a Java progarm to input this and print this Input =a2c3z5 Output = aaccczzzzz */ import java.util.*; class Test { public static void main(String[] args) { String s="a2c3z5"; String[] s2=s.split("(?<=\\G..)"); for(String s3:s2) { char c=s3.charAt(0); int n=s3.charAt(1)-48; for(int i=0;i<n;i++) { System.out.print(c); } } }...

WAP to print char occurrence in given string I/P : s=anand s2=prabhakar O/P : 3a 0n a n 0d

/* WAP to print char occurrence in given string I/P : s=anand   s2=prabhakar O/P : 3a 0n a n 0d */ import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String[] args) { String s="anand"; String s2="prabhakar"; String s3=""; for(int i=0;i<s.length();i++) { String ch=String.valueOf(s.charAt(i)); ...

Write a Java Program to print char occurrence in given string I/P : aabbccadc O/P : 3a 2b 3c 1d

/* Write a Java Program to print char occurrence in given string I/P : aabbccadc O/P : 3a 2b 3c 1d */ import java.util.regex.*; public class Test { public static void main(String[] args) { String s="aabbccadc"; String s4=""; for(int i=0;i<s.length();i++) { String ch=String.valueOf(s.charAt(i)); if(!(s4.contains(ch))) { Pattern p=Pattern.compile(ch); ...

Wednesday, March 14, 2018

WAP in Java to count occurrence of each character of given string.

/*    Count occurrence of each character of given string    Input:-"Sriman java group"    Output:- S-1, r-2, i-1, m-1, a-3, n-1, J-1, v-1, G-1, o-1, u-1, p-1  */ import java.util.regex.Matcher; import java.util.regex.Pattern; public class CharOccurance { public static void main(String[] args) { String s = "Sriman Java Group"; String...