I don't know what's wrong with one of my variable.[Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'm'] -


import java.util.scanner;  public class labex03 {     public static void main(string[] args)     {              system.out.println("name le01");             scanner kbd = new scanner(system.in);             double m = 3;             double n = 0;             system.out.print("type 12 , press enter");             n = kbd.nextint();             double p = (double)m * (double)n;             double q = 0;             q = (double)math.sqrt(p);             system.out.printf("%m");             system.out.printf("%n");             system.out.printf("%p");             system.out.printf("%q");     } }  

debug:

name le01 type 12 , press enter12 exception in thread "main" java.util.unknownformatconversionexception: conversion = 'm' @ java.util.formatter$formatspecifier.conversion(formatter.java:2691) @ java.util.formatter$formatspecifier.(formatter.java:2720) @ java.util.formatter.parse(formatter.java:2560) @ java.util.formatter.format(formatter.java:2501) @ java.io.printstream.format(printstream.java:970) @ java.io.printstream.printf(printstream.java:871) @ labex03.main(labex03.java:16) java result: 1 build successful (total time: 6 seconds)

you've misunderstood supposed in format string % signs. variable names don't go in format string, passed separate parameters printf. format specifier indicates type of variable passed in, e.g. %d integers, %f floating-point numbers, , %s string text.

try e.g.:

system.out.printf("%f", m); 

for further reference, see formatter javadocs, gives more detail how format strings , pass in variables.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -