[Solved]Java Rewrite Following Code Inputs File File Name Input User Scanner Code Import Javautil Q37205108
JAVA: Rewrite the following code to where the inputs are from afile. The file name will be from the input from the userscanner.
CODE:
import java.util.*;
public class Q1
{
public static int sumOD (int k)
{
int sumOD = 0;
int in = k;
while (in != 0)
{
int digitON = in % 10;
sumOD += digitON;
in /= 10;
}
return sumOD;
}
public static void main(String[] args)
{
int n, i, k;
System.out.println(“Enter the number of integers: “);
Scanner keyboard = new Scanner(System.in);
n = keyboard.nextInt();
for (i = 0; i < n; i++)
{
System.out.println(“Enter the number: “);
Scanner keyboard2 = new Scanner(System.in);
k = keyboard2.nextInt();
if (k < 0)
System.out.println(“The integer is negative.”);
else
System.out.println(“The sum of digits is: ” + sumOD(k));
}
}
}
Expert Answer
Answer to JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user… . . .
OR

