Hi guys,
I'm new and I'm totally stuck on a question for class! Basically we have to get the user to enter a few sentences and then change the first letter of every sentence to a capital version. I'll post my code below.
(I'm not asking for the answer just some help would be nice!)

import java.util.*;
public class CH10Q3
{
    public static void main(String[] args)
    {
        String input;
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Please enter a couple sentences");
        input = keyboard.nextLine();
        int periods=0;
        
        while(periods!=-1)
        {
            System.out.println("While Start");
            periods = input.indexOf('.', periods+3);
            System.out.println(periods);
            if(periods!=-1)
                Character.toUpperCase(input.charAt(periods));
            System.out.println("While End");
        }
        System.out.println(input);
    }
}

Okay heres a small update, I am converting my string into a buffered string so its mutable. Here is the code I have now, only problem is it goes out of range!

import java.util.*;
public class CH10Q3
{
    public static void main(String[] args)
    {
        String input;
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Please enter a couple sentences");
        input = keyboard.nextLine();
        StringBuffer input2 = new StringBuffer(input);
        int periods=0;
        
        while(periods!=-1)
        {
            System.out.println("While Start");
            periods = input2.indexOf(".", periods+2);
            System.out.println(periods);
            if(periods!=-1)
            {
                Character.toUpperCase(input2.charAt(periods));
                System.out.println(Character.toUpperCase(input2.charAt(periods+2)));
            }
            System.out.println("While End");
        }
        System.out.println(input2);
    }
}

Any suggestions would be lovely.

Ah well I figured it out on my own.
First problem was I was trying to modify a immutable object.
Second was I was going waaay out of range.

Heres the finaly code

import java.util.*;
public class CH10Q3
{
    public static void main(String[] args)
    {
        String input;
        Scanner keyboard = new Scanner(System.in);
        
        System.out.println("Please enter a couple sentences");
        input = keyboard.nextLine();
        StringBuffer input2 = new StringBuffer(input);
        int periods=0;
        
        input2.setCharAt(0, Character.toUpperCase(input2.charAt(0)));
        
        while(periods!=-1)
        {
            periods = input2.indexOf(".", periods+2);
            if((periods!=-1)&&(periods<(input.length()-2)))
            {
                input2.setCharAt(periods+2, Character.toUpperCase(input2.charAt(periods+2)));
            }
        }
        System.out.println(input2);
    }
}

(This post is like my "I did it WOOO HOOOOO" )

That is what often happens if you not sitting on your back-side and waiting for others to solve your issue...
Nicely done

Haha, thanks. Well I see so many people asking for the answers, and that's not going to help me with my Comp. Sci. Degree... plus I want to be able to write nice software without having to ask people around me constantly for help.

This question has already been answered. Start a new discussion instead.