Course Hero Logo

FileParser.java - import import import import...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 - 3 out of 4 pages.

import java.io.FileNotFoundException;import java.io.*;import java.util.NoSuchElementException;import java.util.Scanner;public class FileParser {public static void main(String[] args) throws IOException {/** --------------------* WORKING WITH STRINGS* -------------------- */String str = "my string";System.out.print("Printing String object 'str' one character at a time: ");for(int i = 0; i < str.length(); i++)System.out.print(str.charAt(i));System.out.println("\n");System.out.println("ASCII value of character at position 2: " + (int)str.charAt(2));System.out.println("ASCII value of character at position 4: " + (int)str.charAt(4));System.out.println("Character at position 4: " + str.charAt(4));char[] a = {'T', 'H', 'E'};/** If we attempt to make a String from the character array 'a' usingthe code* String strA = (String)a;* the compiler throws the error "Cannot cast from char[] to String"*/String strA = new String(a);System.out.println("\nString made from character array {'T', 'H', 'E'}: " + strA);char[] b = {84, 72, 69};String strB = new String(b);System.out.println("String made from character array {84, 72, 69}: " + strB); // See ASCII table/** -----------------* STRING COMPARISON* -----------------*/String str1 = "hello";String str2 = str1;if(str1 == str2)System.out.println("\nReference variables str1 and str2 point to the same object");String str3 = "hello";String str4 = "hello"; // Does not create a new objectif(str3 == str4) System.out.println("Reference variables str3 and str4 point tothe same object");
String str5 = "hello";String str6 = new String("hello");if(str5 == str6) System.out.println("Reference variables str5 and str6 point tothe same object");if (str5.equals(str6))System.out.println("Reference variables str5 and str6 have thesame value");/** -------------* READING FILES* -------------*/System.out.print("\nEnter the name of file to open: ");/*

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 4 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
Backman,Robert
Tags
Filename, Filename extension, Computer file, ASCII, String literal

Newly uploaded documents

Show More

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture