Computer Science, asked by adnan366, 11 months ago

Write a program in java to print a city's name.


Anonymous: just print no input?
adnan366: You have to write input
Anonymous: we will input the city's name and print it?
adnan366: If you only want to write its input..then no problem

Answers

Answered by Anonymous
5

CODE :-

import java.util.*;

class City_name

{

public void main()

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter the city name I will print it");

String s=sc.nextLine();

System.out.println("The city name is :"+s);

}

}

OUTPUT

Enter the city name I will print it

Kolkata

PRINT

Kolkata

___________________________________________________________________

Answered by StaceeLichtenstein
2

Following are the program that is given below

Explanation:

import java.util.*; // import package

public class Main // main class

{

public static void main(String[] args) // main method

{

Scanner sc1=new Scanner(System.in); // create the object of scanner class

System.out.println("Enter the city :");

String s1=sc1.nextLine(); // Read the city

System.out.println("city is :"+s1); // display city

}

}

Output:

Enter the city :

kolk

city is :kolk

Following are the description of program

  • Create the instance of scanner class for input i.e "sc1".
  • Read the city in the 's1" variable by using the scanner class object .
  • Finally display the city by using system .println.

Learn More :

  • brainly.in/question/10342288

Similar questions