Download presentation
Presentation is loading. Please wait.
Published byVictor Sims Modified over 6 years ago
1
COMPUTER 2430 Object Oriented Programming and Data Structures I
2
File Input import java.io.*; Import java.util.Scanner;
public static void main( String args[] ) { Scanner stdin = new Scanner( System.in ); // comment out before submitting to the grader try stdin = new Scanner( new File("Lab6_1.in") ); } catch (Exception ex) System.out.println(ex.toString()); ...
3
String Method split import java.io.*; Import java.util.Scanner;
public static void main( String args[] ) throws IOException { Scanner stdin = new Scanner( System.in ); . . . String cmdLine; String tokens[]; cmdLine = stdin.nextLine(); // “ ” // space “ ” is the only delimiter tokens = cmdLine.split(" "); // tokens[0]: “243.15” // tokens[1]: “5” ... }
4
Parse Methods String cmdLine; String tokens[];
cmdLine = stdin.nextLine(); // “ ” tokens = cmdLine.split(" "); // tokens[0]: “243.15” // tokens[1]: “5” double dbl = Double.parseDouble(tokens[0]); int qVal = Integer.parseInt(tokens[1]);
5
The First Token! import java.io.*; Import java.util.Scanner;
public static void main( String args[] ) throws IOException { Scanner stdin = new Scanner( System.in ); . . . String cmdLine; String tokens[]; cmdLine = stdin.nextLine(); // “ ” tokens = cmdLine.split(" "); // tokens[0]: “” // tokens[1]: “243.15” // tokens[2]: “5” ... }
6
Parsing String for Date
String to parse: “9/30/2009” Delimiter: “/” cmdLine = stdin.nextLine(); tokens = cmdLine.split(“/"); // tokens[0] = “9” // tokens[1] = “30” // tokens[2] = “2009” // Convert to integer int day = Integer.parseInt(tokens[1]);
7
Parsing String for Complex
String to parse: “(3.5,7.213)” Delimiters: “(,)” cmdLine = stdin.nextLine(); tokens = cmdLine.split(“[(,)]"); // tokens[0] = “” // tokens[1] = “3.5” // tokens[2] = “7.213” // Convert to double Double real = Double.parseDouble(tokens[1]);
8
Programming Grand Rules
Most the same as CS 1430 Each line has at most 78 columns Indent 3 spaces No tab keys Braces on separate lines One space before and one space after operator
9
Formatting Setting K:\academic\csse\software\ NetBeans_8.1_JDK_8u91\NetBeans.txt NetBeansSettings.zip
10
NetBeans Formatting Tools->Options->Editor->Formatting tab Select All Languages Select Tabs And Indents Check: Expand Tabs to Spaces Number of Spaces per Indent: 3 Tab Size: 3 Right Margin: 78
11
NetBeans Formatting Tools->Options->Editor->Formatting tab Select Language Java Select Tabs And Indents Continuation Indent Size: 6 Select Braces Select New Line for all under Braces Placement Select Generate for all under Braces Generation Select Alignment Check : else, finally, while, catch Uncheck: after modifier Uncheck all under Multiline Alignment Select Comments Uncheck: Add Leading Star
12
NetBeans Formatting Tools->Templates Select Java then Java class Click Open in Editor Change <#assign licenseFirst = "/*"> to <#assign licenseFirst = "/**"> (adding one "*") Change <#assign licensePrefix = " * "> to <#assign licensePrefix = ""> (" * " to "") Change <#assign licenseLast = " */"> to <#assign licenseLast = "*/"> (removing space in " */")
13
NetBeans Formatting Tools->Templates Change /** * ${user} */ ${user}
14
NetBeans Formatting Tools->Templates Change public class ${name} { } to public class ${name} {
15
NetBeans Formatting Turn off NetBeans updates: Tools --> Plugins --> Settings tab Automatically Check for Updates, Check Interval = Never
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.