+ 2
Java : string input (line) and string concatenation
A String variable is already defined, take another line as input from user, then print predefined string + line input by user
9 Antworten
+ 4
It will work if you add this line at the top of the code:
import java.util.Scanner;
+ 2
Tanaya Seth Can you post the code you tried? I typed the code you posted and mine works just fine.
+ 1
Try the code in this way
package start
import java.util.Scanner;
public class Hello{
public static void main(String[]args){
String s =,,"Hello";
Scanner sc = new Scanner (System.in);
String s1 = sc.next();
System.out.println(s+s1)
It succeeded for me
+ 1
Alright it's running here. Weird. Not running on Eclipse. Thanks Mohamed Izad ! Thanks Kilowac!
https://code.sololearn.com/c6w12mSIa230/?ref=app
0
I tried this but not working:
String s = "Hello";
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
System.out.println(s+s1);
0
Oh that I did. Still not working :(
0
sc.next() takes the line input. But prints only the first word in the line after String s
0
Dunno then
0
I too use eclipse it runs better in neon version.