zoukankan      html  css  js  c++  java
  • Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier 's'

    1、错误描述

    Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier 's'
    	at java.util.Formatter.format(Formatter.java:2487)
    	at java.io.PrintStream.format(PrintStream.java:970)
    	at java.io.PrintStream.printf(PrintStream.java:871)
    	at com.you.example.ArrayExample.main(ArrayExample.java:56)

    2、错误原因

    /**
     *
     * 项目名称:DABF
     * 项目包名:com.you.example
     * 文件名称:ArrayExample.java
     * 类型名称:ArrayExample
     * 创建作者:游海东
     * 创建日期:2017-1-7
     * 创建时间:下午2:58:36
     * 项目版本:V1.0
     */
    package com.you.example;
    
    import java.util.ArrayList;
    
    /**
     * 文件名称:ArrayExample.java
     * 文件类型:ArrayExample
     * 文件包名:com.you.example
     * 创建作者:游海东
     * 创建日期:2017-1-7
     * 创建时间:下午2:58:36
     */
    public class ArrayExample 
    {
    
    	/**
    	 * 方法描述:
    	 * 创建作者:游海东
    	 * 创建日期:2017-1-7
    	 * 创建时间:下午2:58:36
    	 * 方法名称:main
    	 * 方法类型:ArrayExample
    	 * 返回类型:void
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		ArrayList<String> strList = new ArrayList<String>();
    		strList.ensureCapacity(3);
    		strList.trimToSize();
    		strList.add(0, "A");
    		strList.add(1, "B");
    		strList.add(2, "C");
    		strList.add(3, "D");
    		strList.add("E");
    		for(int i=0;i<strList.size();i++)
    		{
    			System.out.println(strList.get(i));
    		}
    		
    		int x = Integer.parseInt("34");
    		System.out.println(Integer.reverse(x));
    		
    		System.out.printf("%d %s",23);
    	}
    
    }
    
          打印printf时,“23”是一个数值类型,格式化不能用“%d %s”

    3、解决办法

    /**
     *
     * 项目名称:DABF
     * 项目包名:com.you.example
     * 文件名称:ArrayExample.java
     * 类型名称:ArrayExample
     * 创建作者:游海东
     * 创建日期:2017-1-7
     * 创建时间:下午2:58:36
     * 项目版本:V1.0
     */
    package com.you.example;
    
    import java.util.ArrayList;
    
    /**
     * 文件名称:ArrayExample.java
     * 文件类型:ArrayExample
     * 文件包名:com.you.example
     * 创建作者:游海东
     * 创建日期:2017-1-7
     * 创建时间:下午2:58:36
     */
    public class ArrayExample 
    {
    
    	/**
    	 * 方法描述:
    	 * 创建作者:游海东
    	 * 创建日期:2017-1-7
    	 * 创建时间:下午2:58:36
    	 * 方法名称:main
    	 * 方法类型:ArrayExample
    	 * 返回类型:void
    	 * @param args
    	 */
    	public static void main(String[] args) 
    	{
    		ArrayList<String> strList = new ArrayList<String>();
    		strList.ensureCapacity(3);
    		strList.trimToSize();
    		strList.add(0, "A");
    		strList.add(1, "B");
    		strList.add(2, "C");
    		strList.add(3, "D");
    		strList.add("E");
    		for(int i=0;i<strList.size();i++)
    		{
    			System.out.println(strList.get(i));
    		}
    		
    		int x = Integer.parseInt("34");
    		System.out.println(Integer.reverse(x));
    		
    		System.out.printf("%d",23);
    	}
    
    }
    


  • 相关阅读:
    Oracle 在64位机器上使用plSQL连接Oracle的问题(SQL*Net not properly installed)
    Bytes to be written to the stream exceed the Content-Length bytes size specified 解决方法
    Eclipse下建立geoserver源码工程
    (转)HttpWebRequest以UTF-8编码写入内容时发生“Bytes to be written to the stream exceed the Content-Length bytes size specified.”错误
    为nginx创建windows服务自启动
    (转)Nginx反向代理设置 从80端口转向其他端口
    从SNE到t-SNE再到LargeVis
    K NEAREST NEIGHBOR 算法(knn)
    从0开始用python实现神经网络 IMPLEMENTING A NEURAL NETWORK FROM SCRATCH IN PYTHON – AN INTRODUCTION
    Python和数据科学的起步指南
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313986.html
Copyright © 2011-2022 走看看