Просто включите name
в сообщение для ввода, например
import java.util.Scanner;
public class Main {
private String name;
private Scanner sc = new Scanner(System.in);
public Main() {
this.name = "default";
}
public String getName() {
return name;
}
public void modify() {
System.out.print("Enter a new name to modify or just press enter to delete the current name, '" + name + "': ");
String str = sc.nextLine();
this.name = str;
}
public static void main(String[] args) {
Main m = new Main();
m.modify();
System.out.println("Name is: " + m.getName());
}
}
Пробный прогон:
Enter a new name to modify or just press enter to delete the current name, 'default': Marius Magaud
Name is: Marius Magaud
Другой примерный прогон:
Enter a new name to modify or just press enter to delete the current name, 'default':
Name is: