Write a program that prompts for and reads the user\'s city and country (separat
ID: 3572299 • Letter: W
Question
Write a program that prompts for and reads the user's city and country (separately). Then print a string composed of the first two letters of the user's country, followed by a comma and then followed by user's city, followed by a random number in the range 1 to 100 which represents the pin code of the city. Similar patterns of representation are sometimes used to store user's address when a new account is registered. Write a declaration for an enumerated type that represents the months of the year.Explanation / Answer
1.
import java.util.*;
import java.lang.*;
import java.io.*;
class StringManipulations
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
String city,country;
System.out.println("Enter user's city");
city = scan.next();
System.out.println("Enter user's country");
country = scan.next();
Random random = new Random();
int randomNumber = 1+ random.nextInt(100);
System.out.println(country.substring(0,2)+","+city +randomNumber);
}
}
output:
2. enum Month{January,February,March,April,May,June,July,August,September,October,November,December};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.