Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads a file from a standard input and rewrites the file to

ID: 3824071 • Letter: W

Question

Write a program that reads a file from a standard input and rewrites the file to standard output, replacing alt tab characters ' ' with the appropriate number of spaces. Make the distance between tab columns a constant and set It to 3. Then expand tabs to the number of spaces necessary to move to the next tab column. That may be less than three spaces. For example, consider the line containing " | I ". The first tab Is changed to three spaces, the second to two spaces, and the third to one space.

Explanation / Answer

import java.util.Scanner;
public class ToSpaceTester
{
public static void main(String args)
{
ToSpace ts= new ToSpace();
System. out .print( "Enter a sentence with tabs to convert to spaces." );
Scanner in= new Scanner(System. in );
System. out .println(ts.spaces(in.nextLine()));
}
}
public class ToSpace
{
public ToSpace()
{

}
public String spaces(String a)
{
String s=a.replace( " " , "...... " ).replace( " " , "..... " ).replace( " " , "..." );
return s;
}
}