So I just started taking my first classing in programming with Java, so don't hurt me for being a new guy. I understand this may be a simple thing to do, but I'm stuck on where to even begin. I want to make a program that simply counts the number of characters in a string using the Scanner utility. So far I have...
import java.util.scanner
class Counter
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Type a sentence, and I will tell you how many
characters are in it.");
String sentence = input.nextString();
And this is as far as I have gotten. What I want to do is the previous plus...
Char character;
and do something with that, maybe a for-loop, but I'm simply stumped. And even if I did want to do this I wouldn't know how to go about it. Any ideas?
Thanks! ~Andrew
EDIT:
import java.util.Scanner;
class Counter
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Type a sentence, and I will tell you how many
characters are in it.");
String sentence = input.nextLine();
sentence = sentence.trim();
System.out.print("This sentence has " + sentence.length() + "
characters in it.");
}
}
Did not seem to work.