+ 1

How do I differentiate 2 inputs in a system input?

For instance I want to print out the second line in a system input How do I do this Ex: 12 13 76 I want to print out the second line (the 13) Help please Update: Apparently my question wasn't clear enough The ex is actually the system input I want to only print out the second line of the system input-not the third or the first

14th Dec 2017, 4:51 PM
Clarke
Clarke  - avatar
8 odpowiedzi
+ 22
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String firstline = sc.nextLine(); String secondline =sc.nextLine(); System.out.println("Your input was :::\n" + firstline +"\n"+secondline); } } //here is ur modified code , for taking 2 lines of input ☺
14th Dec 2017, 7:32 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 19
actually, we use "\n" in SOP() ... to provide a line break "System.out.print (x+"\n");" is same as "System.out.println(x);" //here is ur answer int x=12,y=13,z=76; m1) System.out.println(x);System.out.println(y);System.out.print(z); m2) System.out.print(x+"\n"+y+"\n"+z); m3)System.out.print("12\n13\n76); //as said by meharban singh //u can replace System.out.print() with System.out.println() in both m1,m2,m3 //hope it helps☺
14th Dec 2017, 5:20 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 19
can u show the code ☺ //we can help
14th Dec 2017, 5:57 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 19
welcome buddy☺
14th Dec 2017, 8:27 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
System.out.print("12\n13\n76"); \n means a new line. Alternatively, you can use System.out.println(); or printf()
14th Dec 2017, 5:17 PM
Meharban Singh
Meharban Singh - avatar
+ 1
Thanks guys,but apparently my question wasn't clear enough The ex is actually the system input I want to only print out the second line of the system input-not the third or the first Thanks
14th Dec 2017, 5:51 PM
Clarke
Clarke  - avatar
+ 1
Thank you Gaurav Agrawal 😊
14th Dec 2017, 8:27 PM
Clarke
Clarke  - avatar
+ 1
Thanks now I can write the code I've been wanting to do for days now 😊
14th Dec 2017, 8:32 PM
Clarke
Clarke  - avatar