import java.util.Scanner;
//q1
public class integer {
public void fun()
{
Scanner input = new Scanner(System.in);
int i;
int sum = 0;
int max = -9999;
int min = 9999;
int ne = 0;
int no = 0;
int n;
double ave;
System.out.print("Enter five integers:\n ");
for (i = 1;i <= 5;i++){
n = input.nextInt();
sum = sum + n;
if (n > max)
max = n;
else
min = n;
if (n % 2 == 0)
ne++;
else
no++;
}
ave = (double) sum /5;
System.out.printf("the sum : %d\n",sum);
System.out.printf("the average : %d\n",ave);
System.out.printf("the smallest number : %d\n",min);
System.out.printf("the largest number : %d\n",max);
System.out.printf("the total of odd number is : %d\n",no);
System.out.printf("the total of even number is : %d\n",ne);
}
}هذا الmain
>>>>>>>>>>>>
public class q1 {
public static void main(String[] args){
integer myresult = new integer();
myresult.fun();
}
}output
Enter five integers:
4
2
9
6
10
the sum : 31
the average : Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at integer.fun(integer.java:52)
at q1.main(q1.java:9)


