What is wrong ?
I checked out, the code works.
package com.codegym.task.task18.task1817;
/*
The first parameter of the main method is a file name.
Display the ratio of the number of spaces to the number of all characters. For example, 10.45.
1. Count all the characters (n1).
2. Count the spaces (n2).
3. Display n2/n1*100, rounding to 2 decimal places.
4. Close the streams.
Requirements:
1. You don't need to read anything from the console.
2. Create a stream to read from the file passed as the first argument of the main method.
3. Calculate and display the ratio of the spaces to all characters in the file.
4. The displayed value must be rounded to 2 decimal places.
5. The stream used to read the file must be closed.
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws FileNotFoundException, IOException {
String fileName = args[0];
//String fileName = "d:/data1.txt";
int numberSpaces = 0, numberLetters = 0;
FileInputStream inputStream = new FileInputStream(fileName);
int data;
while (inputStream.available() > 0) {
data = inputStream.read();
if ((data > 64 && data < 91) || (data > 96 && data < 123)) numberLetters++;
if (data == 32) numberSpaces++;
}
inputStream.close();
double result = (double)numberSpaces/numberLetters*100;
System.out.println(Math.round(result*100.0)/100.0);
}
}