⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testcount.java

📁 本例演示了怎样统计一串数字中各个数字的个数
💻 JAVA
字号:
import javax.swing.JOptionPane;
import java.lang.String.*;
public class testCount
{
	public static int[] count(String s)
	{
		char []cc=s.toCharArray();
		int []bb=new int[10];
		for(int i=0;i<cc.length;i++)
		{
			if(Character.isDigit(cc[i]))
				bb[cc[i]-'0']++;
		}
		return bb;
	}
	public static void main(String[]args)
	{
		String string=JOptionPane.showInputDialog(null,"Enter a digital string","TestCount",JOptionPane.QUESTION_MESSAGE);
		int []aa=count(string);
		String output="";
		for(int i=0;i<10;i++)
		{
			output=output+"count["+i+"]="+aa[i]+"\n";
		}
		JOptionPane.showMessageDialog(null,output,"testOutput",JOptionPane.INFORMATION_MESSAGE);
	}



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -