So far I have been able to figure out how many characters are in the string, I can't seem to figure out an if statement to check if the character has more than 10 characters and if it does only display the first 10.
import java.text.*
public class StringPracticeCoding
{
public static void main (String[] args)
{
//local constants
//local variables
//phrase input by the user
String sentence = "I am somebody, I am worthy";
/******************** Start main method *****************/
System.out.println("Length of String: " + sentence.length());
System.out.println(sentence.substring(0,10));
yes it has to be an if statement
Aucun commentaire:
Enregistrer un commentaire