repl.it
@Brawn/

Practice String Commands

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*******************************/
/* DIRECTIONS: Below are  four commands you can use with a String.  In the main method, write four lines of code that demonstrate you know what each command does.  Store the result of executing each command in a variable of the appropriate type.  In the comments, note what you *think* the result of the command is.  Then finally, write a print out command (System.out.println()) that will tell you if you are right or not. */
/*******************************/

/*
• int length()
• String substring(int from, int to)
• String substring(int from)          
• int indexOf(String str)             
*/

class Main {
  
  public static void main(String[] args) {
    
    String example = "Here is some text to perform commands on";
 	String word = example.substring(30);
	System.out.println(word);
	String word2 = example.substring(12, 31);
	System.out.println(word2);
	int num = example.indexOf("perform");
	System.out.print(num);
	
    //1) Demonstrate the use of the length method
    
    //2) Demonstrate the use of the substring(int, int) method
    
    //3) Demonstrate the use of the substring(int) method
    
    //4) Demonstrate the use of the indexOf(String) method
    
  }
  
}
?