How to print the first 3 characters of a string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java programming";
 
        String first_3 = s.substring(0, 3);
         
        System.out.println(first_3);
 
    }
}
 
 
 
 
/*
run:
 
jav
 
*/

 



answered Mar 3, 2021 by avibootz

Related questions

1 answer 119 views
1 answer 124 views
1 answer 131 views
1 answer 144 views
1 answer 150 views
...