Given a String (already declared for you as str), do the following:
-
Print out the following: "The first 3 letters of ___ is ___"
For example, if the input is "banana", your output should be "The first 3 letters of banana is ban"
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
System.out.print("in:");
String str = inp.nextLine();
// Don't change the code above! Write your code below
System.out.println("The first 3 letters of "+str+" is "+str.substring(0,3));
}
}
반응형
'Java_beginner(Repl.it) > Auto-Graded-Course(AP CS A)' 카테고리의 다른 글
015 - Conditional Statement Practice 1 (0) | 2019.11.26 |
---|---|
011 - String Methods Practice 2 (0) | 2019.11.26 |
009 - String Methods - substring (0) | 2019.11.26 |
008 - String Methods - indexOf (0) | 2019.11.26 |
007 - String Methods - charAt (0) | 2019.11.26 |