/* TXT file contains these characters: Pebbles Flintstone\n 1 2.2\n This is a line of text.\n */ import java.io.File; import hava.util.Scanner; Scanner scanner = new Scanner(new File("input.txt")); String s1 = scanner.next(); //s1 is assigned "Pebbles" String s2 = scanner.next(); // s2 is assigned "Flintstone" int x = scanner.nextInt(); // x is assigned 1 double y = scanner.nextDouble(); // y is assigned 2.2 scanner nextLine(); //Advances scanner to beginning of next line String s3 = scanner.nextLine(); // s3 is assigned "This is a line of text" scanner.close();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter