Reputation: 73
I am trying to take input with print statement. How take input from the user in same place ?
package hello;
import java.util.Scanner;
public class hello {
public static void main(String[] args) {
int number;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number: ");
number = sc.nextInt();
sc.close();
System.out.println("Number Entered: "+number);
}
}
Program output
Enter Number:
10
Number Entered: 10
I want to take input in first line
Enter Number: 10
Number Entered: 10
Upvotes: 1
Views: 1217
Reputation: 1619
In Java System.out.println()
means print a line after printing the passed string. Insted of println()
call another function named print()
it will just print the string without returning a new line.
So, replace System.out.println("Enter Number: ");
line into System.out.print("Enter Number: ");
Upvotes: 0
Reputation:
Just use print()
instead of println()
.
System.out.print("Enter Number: ");
Upvotes: 2