Problems with the operator -
I can't seem to get the last part of this to work. Keeps giving error that I can't use this operator. This is only my fifth week of working on Java and any advice would be great. Thanks and here is the code.
public class Assignment2 {
// main(): application entry point
public static void main(String[] args) throws IOException {
// set up the input stream
Scanner stdin = new Scanner(System.in);
// prompt and extract the first and last names
System.out.print ("Enter your first name: ");
String firstName = stdin.nextLine();
System.out.print ("Enter your last name: ");
String lastName = stdin.nextLine();
//compute the length of the name
int wordLength = firstName.length() + lastName.length();
//displays Full name plus name length
System.out.print ("Hello " + firstName + " " + lastName + ", you have " + wordLength );
System.out.println (" characters in your name." );
//Add uppercase parameter
String upperCaseName = firstName.toUpperCase() + " " + lastName.toUpperCase();
//display message with name in uppercase
System.out.println ("Your name with all capital letters looks like the following: " );
System.out.println ( upperCaseName );
//set initials
String firstInit = firstName.substring (0,1);
String lastInit = lastName.substring (0,1);
//display initials
System.out.println ("Your initials are: " + firstInit + lastInit );
//Ask user for year born
System.out.print ("Now " + firstName + ", please enter the year that you were born in: ");
String yearBorn = stdin.nextLine();
//display year born
System.out.println (yearBorn);
//define current year and calculate age
int currentYear = 2007;
String currentAge = (currentYear - yearBorn);
//subtact current year from year born and display message
System.out.println ("You are " + currentAge + " years old and it is a wonderful age!");
//display exit message
System.out.println ("Goodbye " + firstName + "!");
}
}
Getting error
Assignment2.java:54: operator - cannot be applied to int,java.lang.String
String currentAge = (currentYear - yearBorn);
^
1 error
-jGRASP wedge2: exit code for process is 1.
-jGRASP: operation complete
Message was edited by:
javaGreenhorn

