Please make java program Including as much information as possible. Thank 4. Wri
ID: 3747058 • Letter: P
Question
Please make java program Including as much information as possible. Thank 4. Write a Java program that prompts the user to enter two characters, adds them up and prints the integer value of the result. Below is an example of the execution of the program: Enter first character: a Enter second character: b Result is: 195 5. Write a Java program that prompts the user for two strings, compares them lexicographically and outputs the string in ascending order Write a Java program that generates and prints a random phone number every time the program is executed. The number should be formatted as (xxx) xxx-xxxx. The phone number may not start with 0 or 1. For example, the result of a run could be (345) 455-8999 6.Explanation / Answer
Given below is the code for Question 4. As per Chegg Policy, we are supposed to answer first question only. So request you to post other questions each separately. Thank you
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
import java.util.Scanner;
public class Program4 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int first, second;
System.out.print("Enter first character: ");
first = keyboard.next().charAt(0); //use next() to the string input and then use charAt() to get the first character in the string
System.out.print("Enter second character: ");
second = keyboard.next().charAt(0);
int res = first + second;
System.out.println("Result is: " + res );
}
}
output
-----
Enter first character: a
Enter second character: b
Result is: 195