-1

I want to sum up this information that the user typed in. How can I implement it without too much change?

Console output

Vorname(First Name) : Max
Name(Last Name) : Mustermann
Adresse(adress): Musterstraße 1.
Telefon(Phone Number): 030/12345678

Code

import java.io.*;
public class InformationsEingabeBD {
    public static void main(String[] args)throws IOException {
        String str;
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

        System.out.print("Vorname : ");
        str = input.readLine();

        System.out.print("Name : ");
        str = input.readLine();

        System.out.print("Adresse: ");
        str = input.readLine();

        System.out.print("Telefonnummer: ");
        str=input.readLine();

        Integer.parseInt(str);
    }
}
Peter Gordon
  • 1,075
  • 1
  • 18
  • 38
burakburi
  • 23
  • 1
  • 7

1 Answers1

0

Since this looks like a basic assignment, I assume you're not allowed utility classes like StringBuilder. So just assign each input to a variable and output these accordingly.

String firstName = input.readLine();
String lastName = input.readLine();
String address = input.readLine();
String telNr = Input.readLine(); //cast if necessary

Now output the values:

System.out.println("Vorname: "+firstName);
System.out.println("Nachname: "+lastName);
System.out.println("Adresse: "+address);
System.out.println("Telefon: "+telNr);

Or if you need to create one whole string append each input to the resulting string. E.g.

String res = "Vorname: "+input.readLine();
res += " Nachname: "+input.readLine();
//and so on

Note that usually you should avoid concatenation directly on a string object, since a new string object is created each time. Use StringBuilder for example. (See Why StringBuilder when there is String? for more information).

Community
  • 1
  • 1
eol
  • 23,236
  • 5
  • 46
  • 64