Mr. Truncale - Robert E. Lee High School
  • Home
  • Digital Media
    • HTML
  • Video Game Design
  • Comp. Programming I
  • Comp. Programming II
  • AP Computer Science
  • 3D Printing
  • Teacher Resources
  • Contact Me

Java - String Methods 1


Use all the String methods we've learned
Make a class called StringMethods. Get the input (String) sentence [>= 5 characters]. 
  • Printout how long the sting is ( length() )
  • Printout just the characters from 3-end
  • Printout characters 2-5;
  • Printout the 3rd to last character HINT: You will have to use the length() method
  • Printout the index of the first occurrence of the letter 'e'
  • Printout the index of the first occurrence of the String "re"
  • Printout the string with all the 'e' characters changed to '*'
  • Printout the String in all upper case characters
  • Printout the String in all lower case characters
//SAMPLE CODE

//DECLARE VARIABLES
String sentence;
Scanner keyboard = new Scanner(System.in);

//GET INPUT FOR WORD
System.out.println("Enter a sentence with more than 5 characters: ");
sentence = keyboard.nextLine(); //remember nextLine() gets more than one word

//PRINT OUT RESULTS
TURN IN

Powered by Create your own unique website with customizable templates.