1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/* Compare Two Java char Arrays Example This java example shows how to compare two char arrays for equality using Arrays.equals method. */ import java.util.Arrays; public class CompareCharArraysExample { public static void main(String[] args) { //create character arrays char[] charArray1 = new char[]{'d','h','r','f'}; char[] charArray2 = new char[]{'d','h','r','f'}; /* To compare two char arrays use, static boolean equals(char array1[], char array2[]) method of Arrays class. It returns true if both arrays are equal. Arrays are considered as equal if they contain same elements in same order. */ boolean blnResult = Arrays.equals(charArray1,charArray2); System.out.println("Are two char arrays equal ? : " + blnResult); /* Please note that two char array references pointing to null are considered as equal. */ } } /* Output of the program would be Are two char arrays equal ? : true */ |
Do this Using Array of Staring, Get Username and ph no from the user in run time and store it. User then should be able to find out the user name for given ph and vice versa..
Array of string*
public class GlobalMembersStringtoint
{
public static int Main()
{
int k = 0,m,n,eleCount,i,j,count = 0,ch;
int[] newarray = new int[90];
String String = new String(new char[100]);
String pattern = new String(new char[10]);
System.out.print(“enter the string \n”);
fgets(String, 100, stdin);
System.out.print(“enter the pattern \n”);
fgets(pattern, 100, stdin);
m = pattern.length() – 1;
System.out.printf(“\n the length of pattern = %d”,m);
n = String.length() – 1;
System.out.printf(“\n the length of string = %d”,n);
eleCount = n – m;
System.out.printf(“\n number of substrings = %d”,eleCount);
for (i = 0;i <= (n – m);i++)
{
num = 0;
k = i;
for (j = 0;j < m;j++)
{
temp = (int)String.charAt(k);
num = num * 10 + temp;
k++;
}
newarray[i] = num;
System.out.printf(“the value of new array = %d \n”,newarray[i]);
}
num = 0;
for (j = 0;j < m;j++)
{
temp = (int)String.charAt(k);
num = num * 10 + temp;
}
System.out.printf(“number = %d \n”, num);
return 0;
}
}
friends
help me to convert this code into java
i am getting problem ……