Java Format Specifiers
USING FORMAT SPECIFIERS TO PRINT OUTPUT WITH REQUIRED NUMBER OF DECIMAL POINTS
import java.util.Scanner;
public class P03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a;
float b;
char c;
a = sc.nextInt();
b = sc.nextFloat();
c = sc.next().charAt(0);
//System.out.printf("a + "$" + b + "$" + c");
System.out.printf("%d$%.2f$%c", a, b, c);
}
}
Comments
Post a Comment