zoukankan      html  css  js  c++  java
  • s实验2

    2.
    import java.util.Scanner; 
    public class Demo { 
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner scan = new Scanner(System.in);
    while (scan.hasNext()) {
    String str = scan.nextLine();
    String[] str1=str.split(" ");
    int[] num=new int[str1.length];
    for(int i=0;i<str1.length;i++){
    String s=str1[i];
    int k=0;
    for(int j=0;j<str1.length;j++){
    if(s.equalsIgnoreCase(str1[j])){
    k++;
           }
    }
    num[i]=k;
    }
    for(int i=0;i<str1.length;i++){
    for(int j=0;j<str1.length && str1[j]!="-1";j++){
    if(str1[i].equalsIgnoreCase(str1[j]) && i!=j){
    str1[j]="-1";
          }
       }
    }
    for(int i=0;i<str1.length;i++){
    if(str1[i].equals("-1")){
    num[i]=-1;
        }
    }
    for(int i=0;i<str1.length;i++){
    if(!(str1[i].equals("-1"))){
    System.out.println(str1[i]+":"+num[i]);
            }
          }
       }
      }
    }

    单元测试

    public class CountDemo{

       public void demoCount() throws Exception{

          String str=” Hello World My First Unit Test”;

          Count count(str);

    ,   }

    }

    3.

    3、public class aa {

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    String str = "how are you";

    String strs[] = str.split(" ");

    StringBuffer result  = new StringBuffer();

    for(int i = strs.length-1; i >= 0; i--){

    System.out.println(strs[i]);

    result .append(" "+strs[i]);

    }

    System.out.println("倒序:"+result );

    }

    }

  • 相关阅读:
    Merge Sorted Array
    Remove Duplicates from Sorted List
    Integer to Roman
    String to Integer (atoi)
    Valid Parentheses
    3Sum
    Remove Duplicates from Sorted Array
    Swap Nodes in Pairs
    得到一个Object的属性
    在WebGrid中做 批量删除操作
  • 原文地址:https://www.cnblogs.com/bj941020/p/5361336.html
Copyright © 2011-2022 走看看