Computer Science, asked by Linkplayz, 5 hours ago

Write a program to display your name by reading the input from the user.

It is for Java so please help.

Answers

Answered by anusic
0
import java.util.Scanner;
class GetInputs
{
public static void main(String args[])
{
int a;
float b;
String s;
Scanner obj = new Scanner(System.in); /* create a object */
System.out.println("Enter a string:");
s = obj.nextLine(); /* Take string input and assign to variable */ System.out.println("You entered string "+s); /* Print */
System.out.println("Enter an integer:");
a = obj.nextInt(); /* Take integer input and assign to variable */ System.out.println("You entered integer "+a); /* Print */
System.out.println("Enter a float:");
b = obj.nextFloat(); /* Take float input and assign to variable */ System.out.println("You entered float "+b); /* Print */ }
}
Answered by shreyanshsingh644
0

we are gonna see how to accept input from user. We are using Scanner class to get the input. In the below example we are getting input String, integer and a float number. For this we are using following methods:

1) public String nextLine(): For getting input String

2) public int nextInt(): For integer input

3) public float nextFloat(): For float inputExample:

import java.util.Scanner;

class GetInputData

{

public static void main(String args[])

{

int num;

float fnum;

String str;

Scanner in = new Scanner(System.in);

//Get input String

System.out.println("Enter a string: ");

str = in.nextLine();

System.out.println("Input String is: "+str);

//Get input Integer

System.out.println("Enter an integer: ");

num = in.nextInt();

System.out.println("Input Integer is: "+num);

//Get input float number

System.out.println("Enter a float number: ");

fnum = in.nextFloat();

System.out.println("Input Float number is: "+fnum);

}

}

Explanation:

pls mark me as brainliest

Similar questions