zoukankan      html  css  js  c++  java
  • 如何将一串字符串按照某个特定的字符分割后倒叙输出,如:www.baidu.com输出为com.baidu.www

    使用Java处理,并且不能使用spilit方法

    package com.foreverlover;
    
    import java.util.Scanner;
    
    public class FlipString {
    	
    	public static void Filp(String str) {
    		String[] flip = new String[100];
    		char[] ch = str.toCharArray();
    		int flag = 0;
    		flip[flag] = "";//必须初始化为空,否则默认为null
    		for(int i = 0; i < ch.length; i ++)
    			if(ch[i] != '.')
    				flip[flag] += ch[i];
    			else{
    				flag ++;
    				flip[flag] = "";//每次初始化的时候赋值为空
    			}
    		for(int j = flag; j >= 0; j --)
    			if(j != 0)
    				System.out.print(flip[j] + ".");
    			else
    				System.out.println(flip[j]);
    	}
    	
            //测试方法
    	public static void main(String[] args) {
    	         while(true) {
    			Scanner in = new Scanner(System.in);
    			String str = in.nextLine();
    			Filp(str);
    		}
    	}
    }
    

      

  • 相关阅读:
    Vue cmd命令操作
    迭代器和生成器
    10-外键的变种 三种关系
    09-完整性约束
    08-数据类型(2)
    07-数据类型
    06-表的操作
    05-库的操作
    04-基本的mysql语句
    03-MySql安装和基本管理
  • 原文地址:https://www.cnblogs.com/ForeverLover/p/4568454.html
Copyright © 2011-2022 走看看