charl Brown
New Member
- Joined
- Aug 9, 2011
- Messages
- 1
- Reaction score
- 0
- Points
- 1
Hello, I have a question, I was asked to implement a method named codename that asks user to enter their last name
method print first letter
between letter
and last letter
This is my code, it works:
public class codename
{
private String names;
private char first;
private String middle;
private char last;
public codename(String n, char f, String m, char l){
names=n;
char first=f;
middle=m;
char last=l;
first=names.charAt(0);
middle=names.substring(1, names.length()-1);
last=names.charAt(names.length()-1);
}}
import java.util.Scanner;
public class RunMyMethods
{
public static void main (String[] args){
String names = null;
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter your last name: ");
names=scan.next();
System.out.println();
System.out.println("first letter is: " + names.charAt(0));
System.out.println("between letters are: " + names.substring(1, names.length()-1));
System.out.println("last letter is: " + names.charAt(names.length()-1));
}
}
I know I shouldn't have make my class codename, but then where is codename supposed to be, I suspect it should be in place of "names". Please let me know if I am right. I just started programming yesterday.
thanks
method print first letter
between letter
and last letter
This is my code, it works:
public class codename
{
private String names;
private char first;
private String middle;
private char last;
public codename(String n, char f, String m, char l){
names=n;
char first=f;
middle=m;
char last=l;
first=names.charAt(0);
middle=names.substring(1, names.length()-1);
last=names.charAt(names.length()-1);
}}
import java.util.Scanner;
public class RunMyMethods
{
public static void main (String[] args){
String names = null;
Scanner scan=new Scanner(System.in);
System.out.println("Please Enter your last name: ");
names=scan.next();
System.out.println();
System.out.println("first letter is: " + names.charAt(0));
System.out.println("between letters are: " + names.substring(1, names.length()-1));
System.out.println("last letter is: " + names.charAt(names.length()-1));
}
}
I know I shouldn't have make my class codename, but then where is codename supposed to be, I suspect it should be in place of "names". Please let me know if I am right. I just started programming yesterday.
thanks