/* * TabStop * Reads a tab-stop line, then aligns subsequent input lines * with the tab stops. * * Parke Godfrey 2009-11-12 */ import java.io.PrintStream; import java.util.Scanner; public class TabStop { public static void main(String[] args) { PrintStream output = System.out; Scanner input = new Scanner(System.in); output.println("Enter tab mark line:"); String tabMarks = input.nextLine(); String rows = ""; // To accumulate the tab-aligned output rows. output.println("Enter row:"); while (input.hasNext()) { int start = 0; // Position of the first tab stop ('x'). int end; // Position of the next tab (or final) stop. while (start < tabMarks.length() - 1) { end = tabMarks.indexOf("x", start + 1); // (end -start) is the space from this tab stop to the next. rows += String.format("%-" + (end - start) + "." + (end - start) + "s", input.next()); start = end; } rows += "\n"; output.println("Enter row:"); } output.println(tabMarks); output.print(rows); } }