In Java I want to print after press enter to do an input but in the same line, e.g: 'Username: // User input // Other print'.
Doesn't matter if I need to print in the loop or in the find method, if the username is not founded by the method it should print "User not found" after the input in the same line, like this: Username: // if not found -> User not found. I tried verifiying with if user is null but before the find method is late, it prints other line.
User user;
do {
System.out.println(" ");
System.out.print("Username:");
String username = input.nextLine();
user = LogicCtl.findUserByUsername(username);
}
while (user == null);
public User findUserByUsername(String username) {
EntityManager em = getEntityManager();
Query query = em.createQuery("SELECT u FROM User u WHERE u.username = :username");
query.setParameter("username", username);
User user;
try { user = (User ) query.getSingleResult(); } catch (NoResultException e) {
System.out.print(" User not found");
return null;
}
return user;
}