算法竞赛入门经典的java实现之Tex括号->Demo24.java

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36737934/article/details/80209470


下面贴出源码:

package cn.zimo.algorithm;

import java.util.Scanner;

/**
 * TeX括号
 * @author 子墨
 * @date 2018年5月5日 下午8:15:31
 */
public class Demo24 {
    //"To be or not to be,"quoth the Bard ,"That is the question".
    public static void main(String[] args) {
        String str=new Scanner(System.in).nextLine();
        int count=0;
        for(int i=0;i<str.length();i++) {
            if(str.charAt(i)=='"') {
                if(count%2==0) {
                    str=str.replaceFirst("\"", "“");
                }else {
                    str=str.replaceFirst("\"", "”");
                }
                count++;

            }
        }
        System.out.println(str);
    }
}


猜你喜欢

转载自blog.csdn.net/qq_36737934/article/details/80209470