Answer to Question #263641 in Java | JSP | JSF for Jad

Question #263641

Write a Java program to create a new string taking first and last characters from two given strings. If the length of either string is 0 use "#" for missing character.


1
Expert's answer
2021-11-11T00:07:30-0500
import java.util.Scanner;
 public class Main {
 public static void main(String[] args)
 {
    String s1; 
	String s2; 
	Scanner in=new Scanner(System.in);
	System.out.println("Enter first string: ");
	s1=in.next();
	System.out.println("Enter second string: ");
	s2=in.next();
	
	int n = s2.length();
	String res = "";
	res += (s1.length() >= 1) ? s1.charAt(0) : '#';
	res += (n >= 1) ? s2.charAt(n-1) : '#';
	System.out.println(res);
 }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS