char str[10]; strcpy(str,"0123456789");
int judge(){ char str1[]="hello world"; char str2[]="hello world"; char* str3="hello world"; char* str4="hello world"; if(str1==str2){ printf("str1 and str2 are same\n"); } else{ printf("str1 and str2 are not same\n"); } if(str3==str4){ printf("str3 and str4 are same\n"); } else{ printf("str3 and str4 are not same\n"); } return 0; }
public class spaceReplace { public static void spaceReplace(String strOld,int len){ char[] chs =new char[len]; char[] ch = strOld.toCharArray(); for (int i = 0; i < ch.length; i++) { chs[i] = ch[i]; } int strOldLen = 0; int blackString = 0; if(chs==null || len<=0) { new NullPointerException(); } int i=0; while(chs[i]!=‘\0‘){ strOldLen++; if(chs[i]==‘ ‘){ blackString++; } i++; } //将空格转换成%20字符的长度 int strNewLen = strOldLen + blackString*2; if(strNewLen>len){ new ArrayIndexOutOfBoundsException(); } int indexOfOld=strOldLen;//指向‘\0‘ int indexOfNew=strNewLen; while(indexOfOld>0 && indexOfNew>indexOfOld){ if(chs[indexOfOld] == ‘ ‘){ chs[indexOfNew--] = ‘0‘; chs[indexOfNew--] = ‘2‘; chs[indexOfNew--] = ‘%‘; } else{ chs[indexOfNew--] = chs[indexOfOld]; } --indexOfOld; } for (char c : chs) { if(c==‘\0‘){ break; } System.out.print(c); } System.out.println(); } public static void main(String[] args) { String str = "We are happy."; spaceReplace(str,100);//We%20are%20happy. } }
public class arrayMerge { public static void main(String[] args){ int[] A1,A2; A1=new int[]{1,3,5,7,9}; // A1=new int[]{}; A2=new int[]{2,2,3}; // A2=new int[]{2,4,6,8,10}; arrayMerge(A1,A2,100); } public static void arrayMerge(int[] A1,int[] A2,int num){ int[] res=new int[100]; int len1=A1.length; int len2=A2.length; if(len1==0&&len2!=0){ System.out.println(A2); } else if(len1!=0&&len2==0){ System.out.println(A1); } else if(len1==0&&len2==0){ new NullPointerException(); } int mark1=len1-1,mark2=len2-1; int mark=len1+len2-1; while(mark1>=0&&mark2>=0){ if(A1[mark1]>A2[mark2]){ res[mark--]=A1[mark1--]; } else if(A1[mark1]<=A2[mark2]){ res[mark--]=A2[mark2--]; } } // System.out.print("a"); while(mark1<0&&mark2>=0){ res[mark--]=A2[mark2--]; } // System.out.print("b"); while(mark1>=0&&mark2<0){ res[mark--]=A1[mark1--]; } // System.out.print("c"); for(int i=0;i<len1+len2;i++){ System.out.print(res[i]+" "); } } }
原文:https://www.cnblogs.com/ak918xp/p/14421224.html