Computer Science, asked by Anonymous, 9 hours ago

write a program to accept and display a string.​

Answers

Answered by tanwarnikhil207
1

int main() { char z[100];

printf("Enter a string\n"); gets(z);

printf("The string: %s\n", z); return

Answered by anindyaadhikari13
1

Solution:

The problem is solved using Java.

import java.util.*; // Import utility package for taking user-input.

public class Display{ //beginning of class.

   public static void main(String xy[]){ // Beginning of main() method.

       Scanner y=new Scanner(System.in); // Creating object of Scanner class.

       System.out.print("Enter String: "); // Display message.

       String s=y.nextLine(); // Take String as input.

       y.close(); // Scanner close.

       System.out.println("You entered: "+s); // Display the string entered by the user.

   } // main().

} //class.

It is necessary to import scanner class. It allows us to take user input. We can use next() or nextLine() method to take string as input.

See the attachment for output.

Attachments:
Similar questions