StringDemoFinal - "String is '" +

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// File: StringDemoFinal.java // Author: Amber Settle // Course: CSC 211 // This is the version that contains all the changes produced during // the StringDemo recording / import java.util.Scanner; i public class StringDemoFinal { // Create a String object, and call some of its methods / public static void main(String[] args) { /* String sentence = new String("This program uses Strings."); S System.out.println("The String is \"" + sentence + "\"\n"); S System.out.println("The length of the String is " + sentence.length() + "\n"); s System.out.println("The character in position 0 of the String is '" + sentence.charAt(0) + "'\n"); s // How would we create a statement to find the character // in the last position of the String, regardless of what // value is contained in the String? / System.out.println("The character in the last position of the " +
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: "String is '" + sentence.charAt(sentence.length() - 1) +"'\n"); " // We subtract 1 from the length because Strings are indexed // beginning at 0 not at 1 / System.out.println("'O' first appears in position " + sentence.indexOf('O') + "\n"); s System.out.println("\"uses it\" first appears in position " + sentence.indexOf("uses it") + "\n"); s System.out.println("The substring from 5 to 12 is '" + sentence.substring(5, 12) + "'\n"); */ * // Demonstrate how to use the charAt method to obtain a single // character of input from the user / Scanner chScan = new Scanner(System.in); S System.out.print("Enter the letter grade: "); String inputStr = chScan.next(); char grade = inputStr.charAt(0); c System.out.println("The grade entered is " + grade + "\n"); S } }...
View Full Document

Ask a homework question - tutors are online