Java Reference
In-Depth Information
Using hasNextDouble and nextDouble :
input: 6.7
1 total
11. import java.io.*;
import java.util.*;
public class PrintMyself {
public static void main(String[] args)
throws FileNotFoundException {
Scanner input = new Scanner(
new File("PrintMyself.java"));
while (input.hasNextLine()) {
System.out.println(input.nextLine());
}
}
}
12. public static void printEntireFile()
throws FileNotFoundException {
Scanner console = new Scanner(System.in);
System.out.print("Type a file name: ");
String filename = console.nextLine();
Scanner input = new Scanner(new File(filename));
while (input.hasNextLine()) {
System.out.println(input.nextLine());
}
}
13. // pre: no line in input is longer than width
public static void printBox(Scanner input, int width) {
printTopBottom(width);
while (input.hasNextLine()) {
String line = input.nextLine();
System.out.print("| " + line);
for (int i = line.length(); i < width; i++) {
System.out.print(" ");
}
System.out.println(" |");
}
printTopBottom(width);
}
public static void printTopBottom(int width) {
System.out.print("+");
for (int i = 0; i < width + 2; i++) {
Search WWH ::




Custom Search