How do I capitalize the first letter for the returned string at the end? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do I capitalize the first letter for the returned string at the end?

Code is below. It's generating sentences and running I just want the first letter only capitalized. Any help is appreciated thanks! package unit2; public class randomSentence{ static final String[] conjuctions = { "and", "or", "because"}; static final String[] properNoun = { "Chuck", "Charlie", "Jessica", "Geraldine"}; static final String[] commonNoun = { "man", "lady", "dog", "rhino", "pizza", "pepperoni"}; static final String[] determiners = { "a", "the", "this", "that"}; static final String[] intransitiveVerb= {"runs", "rides", "eats", "reads", "plays"}; static final String[] adjectives = { "pretty", "astonishing", "smelly", "huge", "tiny"}; static final String[] transitiveVerb = {"sees", "finds", "summons", "holds", "grabs"}; public static void main(String[] args) { while(true) { randomSentence(); System.out.print(".\n"); try { Thread.sleep(4000); } catch (Exception e) { } } } private static void randomSentence() { randomNounPhrase(); randomVerbPhrase(); if (Math.random() > 0.75) { System.out.print(" " + randomItem(conjuctions)); randomSentence(); } } static void randomNounPhrase() { if(Math.random() > 0.75) System.out.print(" "+ randomItem(properNoun)); else { System.out.print(" " + randomItem(determiners)); if(Math.random()> 0.5) System.out.print(" "+ randomItem(adjectives)); System.out.print(" " + randomItem(commonNoun)); } } static void randomVerbPhrase() { if (Math.random() >= 0.5) System.out.print(" " + randomItem(intransitiveVerb)); else if (Math.random() > 0.5) { System.out.print(" " + randomItem(transitiveVerb)); randomNounPhrase(); } else if (Math.random() > 0.25) System.out.print(" is " + randomItem(adjectives)); else { System.out.print(" thinks"); randomNounPhrase(); randomVerbPhrase(); } } static String randomItem(String[] listofStrings) { return listofStrings[(int)(Math.random

29th Jun 2022, 2:12 AM
Jocelyn
Jocelyn - avatar
3 Answers
+ 2
Jocelyn, The snippet is truncated. For a code that big, you better share a code bit link, only small snippet will fit in post's Description. https://www.sololearn.com/post/75089/?ref=app (Edit) Jocelyn Here's a little test ... https://code.sololearn.com/clE43KfZDMtT/?ref=app
29th Jun 2022, 8:27 AM
Ipang
+ 1
Aaa Bbb stop spamming bro
29th Jun 2022, 2:37 AM
Aly Alsayed
Aly Alsayed - avatar
- 1
Hii
30th Jun 2022, 5:26 AM
Sahil Cholke
Sahil Cholke - avatar