zoukankan      html  css  js  c++  java
  • Java

    public class Test {
        public static void main(String args[]) {
            String str = "helloworld";
            char[] data = str.toCharArray();// 将字符串转为数组
            for (int x = 0; x < data.length; x++) {
                System.out.print(data[x] + "  ");
                data[x] -= 32;
                System.out.print(data[x] + "  ");
            }
            System.out.println(new String(data));
        }
    }

    返回字符串最后一个单词的长度

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner in = new Scanner(System.in);
    if(in.hasNext()) {
    String[] a = in.nextLine().split(" ");
    System.out.println(a[a.length-1].length());
    }else {
    System.out.println(0);
    }
    in.close();
    }

    字符串大小写字母反转

    static StringBuffer sb = new StringBuffer();

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner in = new Scanner(System.in);
    String str = in.nextLine();
    System.out.println(exChange(str));
    in.close();
    }

    public static String exChange(String str) {

    for (int i = 0; i < str.length(); i++) {
    char c = str.charAt(i);
    if (Character.isUpperCase(c)) {
    sb.append(Character.toLowerCase(c));
    } else {
    sb.append(Character.toUpperCase(c));
    }
    }
    return sb.toString();
    }

    字符串反转

    public static String reverse(String str) {
    StringBuffer sb = new StringBuffer();
    for (int i = str.length()-1; i>=0 ; i--) {
    sb.append(str.charAt(i));
    }
    return sb.toString();
    }

     Java输入流

    String str;
    StringBuffer sb = new StringBuffer();

    Scanner sc = new Scanner();

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    do {
    str = br.readLine();
    sb.append(str);
    } while (!str.equals("end"));

    if (sc.hasNextLine()) {
    sb.append(sc.nextLine());
    }

    System.out.println(sb.toString());

  • 相关阅读:
    python列表--查找集合中重复元素的个数
    python3-打印一个进度条
    python3-sys模块
    python3-字符串操作
    python3-深浅复制
    python3-os模块
    接口和抽象类有什么区别
    集合知识
    面向对象的特征有哪些方面
    javadoc时候乱码-编码 GBK 的不可映射字符
  • 原文地址:https://www.cnblogs.com/lhang55/p/7580856.html
Copyright © 2011-2022 走看看