• 编程题


    1.计算字符串最后一个单词的长度,单词以空格隔开。

    import java.util.Scanner;
    public class Main {

      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
      String s="";
      while(input.hasNextLine()){
        s=input.nextLine();
        System.out.println(s.length()-1-s.lastIndexOf(" "));
        }
      }
    }

    2.写出一个程序,接受一个有字母和数字以及空格组成的字符串,和一个字符,然后输出输入字符串中含有该字符的个数。不区分大小写。

    import java.util.*;

    public class Main{

      public static void main(String[] args){
      int count=0;
      Scanner in = new Scanner(System.in);
      String str = in.nextLine().toUpperCase();

      char target = in.nextLine().toUpperCase().toCharArray()[0];

        for(int i=0;i<str.length();i++){
        if(str.charAt(i) == target){
        count++;
        }
      }
      System.out.println(count);

      }

    }

     
  • 相关阅读:
    Linux日志清除
    QT vs x64编译
    VC调用QT的UIDLL
    QT UI获得控件ID(HWND)
    安卓黑客工具
    VMware+Windgb+Win7内核驱动调试
    ubuntu 键盘布局修改
    魅族MX3 smart bar处失灵
    把NDK的工具链提取出来单独使用
    arm指令版本
  • 原文地址:https://www.cnblogs.com/xiaoxiaoccaiya/p/5972219.html
Copyright © 2020-2023  润新知