3
The code below counts how many letters there are in a word and multiplies by 0.01. The problem is that I want when a 10 letter word, for example, is typed, to have an output of 0.10 and not 0.1.
import java.util.Scanner;
import java.text.DecimalFormat;
public class MedidaDeTempo{
public static void main(String[] args){
Scanner ler = new Scanner(System.in);
String teste;
int C, tamanho, i = 0;
double T;
C = ler.nextInt();
do{
i++;
teste = ler.nextLine();
tamanho = teste.length();
T = tamanho * 0.01;
if(T > 0.00){
DecimalFormat df = new DecimalFormat("0.##");
String decimal = df.format(T);
System.out.printf(decimal + "\n");
}
} while(i <= C);
}
}
Thanks! I figured out what I was doing wrong! I was putting "%. 00f" instead of "%. 2f", as you put it.
– Van Ribeiro