现在的位置: 首页 > 综合 > 正文

java面试题(编程类)

2014年01月21日 ⁄ 综合 ⁄ 共 686字 ⁄ 字号 评论关闭

 001

 写一个方法,实现字符串的反转,如:输入exceljava,输出avajlecxe;

public class Reverse{

   public static void main(String[] args)
      {
              String str="exceljava";
              char[] c=str.toCharArray();
              char[] temp=new char[c.length];
              for(int i=0,j=c.length-1;i<c.length;i++,j--)
              {
                      temp[j]=c[i];
              }
              System.out.println(temp);
      }

}

002我们在web应用开发过程中经常遇到输出某种编码的字符,如iso8859-1等,如何输出一个某种编码的字符串?

Public String translate (String str) {
     String tempStr = "";
     try {
       tempStr = new String(str.getBytes("ISO-8859-1"), "GBK");
       tempStr = tempStr.trim();
     }
     catch (Exception e) {
       System.err.println(e.getMessage());
     }
     return tempStr;
   }

【上篇】
【下篇】

抱歉!评论已关闭.