Computer Science, asked by kiranbala7938, 7 months ago

write funtion name to input string types data using scanner class (with space)​

Answers

Answered by huzaifanoman1410
5

Answer:

import java.util.Scanner; // Import the Scanner class

class MyClass {

public static void main(String[] args) {

Scanner myObj = new Scanner(System.in); // Create a Scanner object

System.out.println("Enter username");

String userName = myObj.nextLine(); // Read user input

System.out.println("Username is: " + userName); // Output user input

}

}

Answered by hitanshbansal66
11

Explanation:

I need to read spaces (present before string and after String) given as input using Scanner Note : if there is no spaces given in input it should not add space in output

Please find the below code:

package practise;

import java.util.Scanner;

public class scanccls {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner scan = new Scanner(System.in);

String name= scan.nextLine();

name+=scan.nextLine();

scan.close();

System.out.println("Enter your name"+name);

}

}

I am expecting output like:

Input :Enter Your name:Chandu Aakash

Output:chandu Aakash

Input: Enter Your name: (Space..)Chandu Aakash(Space..)

Output: (space.. )chandu Aakash(Space..)

I HOPE YOU LIKED MY ANSWER.

PLZ FOLLOW...

LIKE AND MARK IT AS BRAINLIST..

THANKS....

YOUR FRIEND SANDHYA....

Similar questions