0
Q
How can I write a java program that will declare two string variables for student names containing first name and last name? Like this: String 1: Jack Wilson String 2: Dean Copper Result» String 1: Jack Copper String 2: Dean Wilson
2 ответов
0
You can doit like this:
public static void main (String[]args) {
Student s1 = new Student("Jack","Copper");
Student s2 = new Student("Dean","Wilson");
s1.display();
s2.display();
}
class Student {
String firstName;
String lastName;
static int count = 1;
Student (String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
void display(){
System.out.println("String "+(count++)+": "+firstName+" "+lastName);
}
}
0
A simple answer using split:
https://code.sololearn.com/c7cvlB1g1mgl/?ref=app