0
I’m new to Java, and I can’t run this code:
package exercicio.pkg4;
import java.util.Scanner;
public class Exercicio4 {
public static void main(String[] args) {
Scanner ler = new Scanner(System.in);
int x[] = new int[10];
int i;
int resto;
for(i=1; i<=10; i++)
{
System.out.printf("Digite o %iº número\n",i);
x[i] = ler.nextInt();
}
for(i=1; i<=10; i++)
{
resto = x[i]%2;
if(resto == 0)
{
System.out.printf("%i <- numero par. ",x[i]);
}else{
System.out.printf("%i <- numero impar. ",x[i]);
}
}
}
}
The following messages appear in the output:
Exception in thread "main" java.util.UnknownFormatConversionException: Conversion = 'i'
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691)
at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2720)
at java.util.Formatter.parse(Formatter.java:2560)
at java.util.Formatter.format(Formatter.java:2501)
at java.io.PrintStream.format(PrintStream.java:970)
at java.io.PrintStream.printf(PrintStream.java:871)
at exercicio.pkg4.Exercicio4.main(Exercicio4.java:16)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 1 segundo)
Change
%iº
for%dº
, resolves?– Costamilam