Please briefly explain why you feel this answer should be reported .

Report

Cancel

import java.util.Scanner;
public class Exercise1 {

public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print(“Input an integer: “);
int digits = in.nextInt();
System.out.println(“The average is “+avgDigits(digits));
System.out.println(“Number of 2 presents in the integer ” + (Digitstwo(digits)));
}

public static double avgDigits(int n){
double result;
double sum = 0;
double nlen = String.valueOf(n).length();
while(n > 0) {
sum += n % 10;
n/= 10;
}
return (double)(sum/nlen);
}

public static int Digitstwo(int n) {
String s = String.valueOf(n);
int result = s.length() – s.replace(“2”, “”).length();
return result;
}
}

## Answers ( 2 )

## Please briefly explain why you feel this answer should be reported .

import java.util.Scanner;

public class Exercise1 {

public static void main(String[] args)

{

Scanner in = new Scanner(System.in);

System.out.print(“Input an integer: “);

int digits = in.nextInt();

System.out.println(“The average is “+avgDigits(digits));

System.out.println(“Number of 2 presents in the integer ” + (Digitstwo(digits)));

}

public static double avgDigits(int n){

double result;

double sum = 0;

double nlen = String.valueOf(n).length();

while(n > 0) {

sum += n % 10;

n/= 10;

}

return (double)(sum/nlen);

}

public static int Digitstwo(int n) {

String s = String.valueOf(n);

int result = s.length() – s.replace(“2”, “”).length();

return result;

}

}

## Please briefly explain why you feel this answer should be reported .

Hello. And Bye.