+ 1

How can I put more than one Scanner on java?

Might be a stupid question, but I just started with java like yesterday or something, but.. Is it possible to have 4 gui's using scanners on java? for example : First name: (input) Last name: (input) Address: (input) Workplace: (input)

4th Jul 2019, 3:26 PM
Irvin Dumagdag
Irvin Dumagdag - avatar
3 Answers
+ 4
Yes, you can, but not on Sololearn. Besides, you don't have to take multiple inputs for this, the Scanner's nextLine method gets an entire line, so you can do something like this: Scanner sc = new Scanner(System.in); String fName = sc.nextLine(); String lName = sc.nextLine(); String adress = sc.nextLine(); String workplace = sc.nextLine(); (Although, for the name, I don't think you need seperate lines - to take one word as an input, you can use the next method)
4th Jul 2019, 3:57 PM
Airree
Airree - avatar
+ 2
an scanner object can get input as many times as you need ... 😅 or do I umderstand your question wrong? import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String in1 = sc.next(); String in2 = sc.next(); //as many as you need ... } }
4th Jul 2019, 3:56 PM
Anton Böhler
Anton Böhler - avatar
+ 2
Anton Böhler and Airree Tysm! This will help me a lot
4th Jul 2019, 4:28 PM
Irvin Dumagdag
Irvin Dumagdag - avatar