如何将void返回类型clear函数转换为字符串返回类型。 [英] How do I convert my void return type clear function to string return type.

查看:100
本文介绍了如何将void返回类型clear函数转换为字符串返回类型。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class stringtowords 
{  
	public static void Clear(String s)
	{
		String wo[]=s.split(" ");
	       for(String w:wo)
	      {
	    	  System.out.println(w);
	      }
	       System.out.println("clear words i.e. after ignoring special characters and no. and converting all to small letters are:");
	      	
	      String word;
	       for(int i=0;i<wo.length;i++)
	       { 
	    	   word=wo[i].toLowerCase();
	    	    List<Character> li=new ArrayList<Character>(); 
	    	    for (char ch:word.toCharArray())
	    	      if(ch>='a' && ch<='z')
	    	      li.add(ch);
	    	    String ss="";
	    	    for(char ch:li)
	    	    ss=ss+ch;
	    	    
	    	    System.out.println(ss);
	      }
	}
	public static void main(String args[])
	{
	   String s="Hello! my my Name@ is Pragya12";
       Clear(s);
      // System.out.println(g);
       
     }    
}





我的尝试:



上面的代码工作正常,但我的Clear函数中没有使用void返回类型,我想使用String返回类型,但我不知道如何.Any帮助将不胜感激。



What I have tried:

the above code is working fine but instead of using void return type in my Clear function,I want to use String return type but I'm not getting it how.Any help would be appreciated.

推荐答案

public static String Clear(String s)
	{
		String sReturn = "";
		String wo[]=s.split(" ");
	       for(String w:wo)
	      {
	    	  return w; // Maybe you need a lineSpace
	      }
	       sReturn = "clear words i.e. after ignoring special characters and no. and converting all to small letters are:";
	      	
	      String word;
	       for(int i=0;i<wo.length;i++)
	       { 
	    	   word=wo[i].toLowerCase();
	    	    List<Character> li=new ArrayList<Character>(); 
	    	    for (char ch:word.toCharArray())
	    	      if(ch>='a' && ch<='z')
	    	      li.add(ch);
	    	    String ss="";
	    	    for(char ch:li)
	    	    ss=ss+ch;
	    	    
	    	    sReturn += ss; // Maybe you need a lineSpace
	      }

	      return sReturn;
	}


这篇关于如何将void返回类型clear函数转换为字符串返回类型。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆