+ 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
8 Réponses
+ 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 ☺
+ 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☺
+ 19
can u show the code ☺
//we can help
+ 19
welcome buddy☺
+ 4
System.out.print("12\n13\n76");
\n means a new line.
Alternatively, you can use System.out.println(); or printf()
+ 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
+ 1
Thank you Gaurav Agrawal 😊
+ 1
Thanks now I can write the code I've been wanting to do for days now 😊