Write a program that asks the user to enter the name of his or her favorite city. Use a string variable to store the input. The program should display the following:
• The number of characters in the city name
• The name of the city in all uppercase letters
• The name of the city in all lowercase letters
• The first character in the name of the city
Here is the code I wrote..
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package stringmanipulator;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
*
* @author Joseph_Barile
*/
public class Main {
public Main() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception {
String CurLine="";
System.out.println(" Please enter your favorite city. ");
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
CurLine = in.readLine();
System.out.println(" Number of Character in City : "+CurLine.length());
System.out.println(" Name of the City (UC) : "+CurLine.toUpperCase());
System.out.println(" Name of the City (LC) : "+CurLine.toLowerCase());
System.out.println(" First Character of the City : "+CurLine.substring(0, 1));
}
}
I am new to Java and NetBeans.. What can I clean up or take out of this code?
Also I am getting an error on the line
public class Main {
It says this.. class main is public, should be declared in a file named Main.java
How do I fix this?

New Topic/Question
Reply



MultiQuote







|