我必须编写一个程序,我在其中输入棒球统计数据,并且它出现了持续击打平均值,然后重新说出了玩家的名字,然后把它放在了一个哨兵循环上.我目前的代码如下.在我把它变成一个循环之前,我试图让它与一个一起工作.当我跑去测试时,我明白了UnknownFormatConversionException.这是什么意思?我该如何修复我的代码?
import java.util.Scanner;
public class bata
{
public static void main(String[] args) throws Exception
{
double ba,sp,tb;
int tri,dou,sin,hr,ab,hits;
String name;
Scanner sc = new Scanner(System.in);
System.out.print("Enter Singles");
sin = sc.nextInt();
System.out.print("Enter Doubles");
dou = sc.nextInt();
System.out.print("Enter Triples");
tri = sc.nextInt();
System.out.print("Enter Homeruns");
hr = sc.nextInt();
System.out.print("Enter At bats");
ab = sc.nextInt();
System.out.print("Enter Player name");
name = sc.nextLine();
System.in.read();
tb= (sin + (dou*2) + (tri *3) +(hr *4));
hits = sin+dou+tri+hr;
sp= tb/ab;
ba= hits/ab;
System.out.println(""+name);
System.out.printf("Slugging % is %.3f\n", sp);
System.out.printf("Batting avg os %.3f\n", ba);
}
}
Run Code Online (Sandbox Code Playgroud)
逃生%标志,使用双%%:
System.out.printf("Slugging %% is %.3f\n", sp);
// ^------------- escaping
Run Code Online (Sandbox Code Playgroud)