package com.altafjava.test;
public class Test {
public static void main(String[] args) {
String s="526";
int sum=0;
for(int i=0;i<s.length();i++){
sum=(sum*10)+(s.charAt(i)-48);
}
System.out.println("Original...
RECENTLY MOST VIEWS
-
For example, If given number 165 a nd given digit is ...
-
Note: An Armstrong number can calculated as follows. ...
-
/* Write a JAVA program for the given string and take...
-
package com.altafjava.test; public class Test { ...
-
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class Jdbc2...
-
package com.cdcis.test; /** * How to count...
MOST POPULAR
-
Note: A number will be called DISARIUM if sum of its...
-
The International Mobile Station Equipment Identity(IMEI)...
-
Harshad Number : In recreational mathematics, a Harshad...
-
package com.altafjava.sln.test; public class...
-
package com.fdcis.test; /** * How to find duplicate...
Blog Archive
-
▼
2018
(38)
-
▼
August
(19)
- How to convert string into int primitive data type?
- Write a JAVA program for the given string and take...
- How to find largest number less than a given numbe...
- How to count occurrences of each character of a st...
- How to count occurrences of each character of a st...
- How to find second largest number in an integer ar...
- How to find sum of all digits of a number in java?
- How to find duplicate elements in an array using H...
- How to find duplicate elements in an array?
- Java Program to check two strings are Anagram or not
- How do you check the equality of two inner arrays ...
- How do you check the equality of two arrays in java?
- How to count duplicate characters in a string in j...
- How to find duplicate characters in a string in java?
- How do you remove all white spaces from a string i...
- How do you remove all white spaces from a string i...
- How to print Number Pyramid Pattern in java?
- How to create a pyramid of numbers in java?
- How to reverse a string in java?
-
►
March
(19)
- Write a Java Program to take an String array like ...
- Write a Java program to take an string array and f...
- Write a JAVA program for the given string and take...
- Write a program in java to find the longest palind...
- Write a program in java to print total palindrome ...
- Write a program in java to check whether an string...
- Write a program in java to check whether an string...
- Write a java program to print this numeric pattern...
- Write a java program to print this numeric pattern...
- Java Program to view System Properties
- How to make our classes as immutable class by usin...
- Write a java program in java to reverse each word ...
- WAP in java to reverse each word of string like ...
- Write a Java Program to reverse an String without ...
- Write a program in java to find the 1st non repeat...
- Write a Java progarm to input this and print this ...
- WAP to print char occurrence in given string I/P...
- Write a Java Program to print char occurrence in g...
- WAP in Java to count occurrence of each character ...
-
▼
August
(19)
About
Hello ALTAF
Friday, August 24, 2018
Thursday, August 23, 2018
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 CheckSubstring
{
public static void main(String[] args)
{
String s="google";
...
How to find largest number less than a given number and without a given digit?
For example, If given number 165 and given digit is 6 then you should find the largest number less than 165 but it should not contain 4 in it. In this case answer is 159.
package com.altafjava.test;
public class FindLargestNo {
public...
How to count occurrences of each character of a string without using Regular Expression in java?
package com.altafjava.coos.test;
public class CountOccurrences2 {
public static void main(String[] args) {
String s="annotation";
System.out.println("Original String = "+s);
while(s.length()!=0){
int count=0;
for(int i=0;i<s.length();i++){
if(s.charAt(0)==s.charAt(i))
...
How to count occurrences of each character of a string in java?
package com.altafjava.coocis.test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CountCountOccurrences {
public static void main(String[] args) {
String s="annotation";
System.out.println("Original String = "+s);
while(s.length()!=0){
int...
Wednesday, August 22, 2018
How to find second largest number in an integer array?
package com.altafjava.sln.test;
public class SecondLargestNumber {
public static void main(String[] args) {
int[] arr={5,20,8,1,9,2,14,34,11};
int largest=Integer.MIN_VALUE;
int secondLargest=Integer.MIN_VALUE;
for(int i=0;i<arr.length;i++){
if(arr[i]>largest){
...
How to find sum of all digits of a number in java?
package com.altafjava.sad.test;
public class SumAllDigit {
public static void main(String[] args) {
int num=9526;
System.out.println("Original number = "+num);
int sum=0;
while(num!=0){
int remainder=num%10;
sum=sum+remainder;
num=num/10;
}
System.out.println("Sum...
Tuesday, August 21, 2018
How to find duplicate elements in an array using HashSet?
package com.altafjava.fdeia.test;
import java.util.HashSet;
public class Test2 {
public static void main(String[] args) {
int[] arr={1,6,5,1,2,2,9,6};
System.out.println("Input Array = 1,6,5,1,2,2,9,6");
System.out.print("The repeating elements...
How to find duplicate elements in an array?
package com.altafjava.fdeia.test;
public class Test {
public static void main(String[] args) {
int[] arr={1,6,5,1,2,2,9,6};
System.out.println("Input Array = 1,6,5,1,2,2,9,6");
System.out.print("The repeating elements are : ");
...
Monday, August 20, 2018
Java Program to check two strings are Anagram or not
An anagram of a string is another string that contains same characters, only the order of characters can be different. For example, “LISTEN” and “SILENT” are anagram of each other.
package com.caots.test;
import java.util.Arrays;
public class Test {
public static void main(String[]...
How do you check the equality of two inner arrays in java?
package com.ceo2a.test;
import java.util.Arrays;
public class Test2 {
public static void main(String[] args) {
int[] arr1={5,6,9};
int[] arr2={5,6,9};
Object[] objArr1={arr1};
Object[] objArr2={arr2};
System.out.println("objArr1 == objArr2 ? "+Arrays.equals(objArr1,...
How do you check the equality of two arrays in java?
package com.ceo2a.test;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] arr1={5,6,9};
int[] arr2={6,5,9};
int[] arr3={5,6,9};
System.out.println("arr1 == arr2 ? "+Arrays.equals(arr1, arr2));
System.out.println("arr1 ==...
Sunday, August 19, 2018
How to count duplicate characters in a string in java?
package com.cdcis.test;
/**
* How to count duplicate characters in a string in java?
*
*/
public class Test {
public static void main(String[] args) {
String s="altafjava.blogspot.com";
System.out.println("Original String = "+s);
int count=0;
for(int...
How to find duplicate characters in a string in java?
package com.fdcis.test;
/**
* How to find duplicate characters in a string in java?
*
*/
public class Test {
public static void main(String[] args) {
String s="altafjava.blogspot.com";
System.out.println("Original String = "+s);
System.out.print("Duplicate...
How do you remove all white spaces from a string in java?
package com.rwsfs.test;
public class Test2 {
public static void main(String[] args) {
String s="Good Morning Mumbai";
StringBuilder sb=new StringBuilder();
for(int i=0;i<s.length();i++){
if(s.charAt(i)!=' '){
sb.append(s.charAt(i));
}
}
System.out.println("Original...
How do you remove all white spaces from a string in java?
package com.rwsfs.test;
public class Test {
public static void main(String[] args) {
String s="My name is khan and i am not a terrorist";
String newString=s.replaceAll("\\s","");
System.out.println("Original String = "+s);
System.out.println("New String = "+newString);
...
How to print Number Pyramid Pattern in java?
package com.npp.test;
public class Test {
public static void main(String[] args) {
int n=9;
for(int i=n;i>=1;i--){
for(int j=n;j>=1;j--){
System.out.print(j>i?" ":i+" ");
}
System.out.println();
}
}
}
How to print Number Pyramid Pattern...
Thursday, August 16, 2018
How to create a pyramid of numbers in java?
package com.npp.test;
public class Test {
public static void main(String[] args) {
int n=10;
for(int i=1;i<=n;i++)
for(int j=1;j<=n+1;j++)
System.out.print(i>9?j<=n-i+1?" ":i+" ":j<=n-i+1?" ":i+" ");
}
System.out.println();
}
...
How to reverse a string in java?
package com.rs.test;
public class Test {
public static void main(String[] args) {
String s="altafjava";
StringBuilder rs=new StringBuilder();
for(int i=s.length()-1;i>=0;i--){
rs.append(s.charAt(i));
}
System.out.println("Original String = "+s);
System.out.println("Reversed...
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);
...
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");
...
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++){
...
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)
...
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 Program to reverse an String without reverse() method
// Write a Java Program to reverse a string without reverse() method
import java.util.*;
class ReverseString
{
public static void main(String[] args)
{
String s="Vishnu";
StringBuffer sb=new StringBuffer("");
for(int i=s.length()-1;i>=0;i--)
sb.append(s.charAt(i));
...
Write a program in java to find the 1st non repeated character from the string.
/*
WAP to find the 1st non repeated character from the string.
In this string ("altaf alam") 1st Non repeat character is 't'
*/
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NonRepeatChar {
public static void main(String[] args) {
String...
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...
Subscribe to:
Posts (Atom)
Program List
- armstrong
- char-occurrances
- check-anagram
- check-duck-no
- check-duplicate-no
- check-endianess-of-os
- check-equality-of-two-arrays
- check-fibonacci-series
- check-harshad-no
- check-kaprekar
- check-keith-no
- check-niven-no
- check-palindrome
- check-prime
- check-prime-no
- check-substring
- check-unique-no
- check-valid-imei
- convert-array-to-list
- convert-string-to-int
- count-duplicate-char-in-string
- count-occurrences-char-of-string
- create-immutable-class
- disarium
- filter-number
- find-1st-non-repeat-char
- find-common-no-in-array
- find-duplicate-char-in-string
- find-duplicate-no-in-array
- find-largest-no-less-than-given-no
- find-palindrome
- find-second-largest-number
- image-store-in-database
- jdbc-program
- number-pyramid-pattern
- numeric-pattern
- remove-duplicate-in-string-array
- remove-white-space-of-string
- reverse-list
- reverse-string
- search-element-in-array
- search-list
- sorting-array
- sorting-list
- sorting-user-defined-object
- string-reverse
- sum-of-all-digits
- swap-2-no
- view-system-properties