Computer Science, asked by ManishShergill2407, 8 months ago

How do you accept data in a variable from the user? Give the syntax of the command along with an example.​

Answers

Answered by divitv2007
3

Answer:

look below

Explanation:

using scanner class

import java.util.*;

//to input a package which contains scanner

public class inputfromuser{

//initialisation of the class

public static void main(){

Scanner in=new Scanner(System.in)

//Scanner can have any name liek a variable

//now , to input the data in a variable

//type int:

int x;

//initialising variable x

x=in.nextInt();

//This is the command for accepting the variable

//you can also change the name of teh scanner to something like test , then the statement to accept would be test.nextInt()

//for other variables please comment .

//I will tell you the answer

}

}//end of class

another method:

in the public static void main() statement , within the bracket just write int x.

like

public static void main(int x)

mark as brainliest

Similar questions