Use Lab 5 practices for guidance to complete the following p

Use Lab 5 practices for guidance to complete the following programs. Required: Use Java assert statement to validate program input values. See Chapter 3 slides for code examples. Apply this requirement to both lab exercises and assignment programs. Write a Java program (name it StringMethods) that reads from the user two strings (say string 1 and string 2). Use String class methods to manipulate these strings as follows Make sure to properly label your output for each manipulation and print the outputs on separate lines. Use the tab escape character to line-up the outputs after the labels as follows: Determine the length of string_1. Determine the length of string_2. Concatenate both strings. Check if the two strings have same set of characters with regard to case (i.e., equal). Convert string_1 to upper case. Convert string_2 to lower case. Extract a valid sub-string of multiple characters from string_1. Separate your code into sections with proper in-line comments such as//Part A: Determine in length of string_1 Write a Java program (name it RandomNumbers) that generates random numbers as follows. Make sure to properly label your output for each part below and print the outputs on separate lines As in the previous program, use the tab escape character to line-up the outputs after the labels. A random integer number between 30 and 50 (inclusive). A random integer number between 20 and -20 (inclusive). A random integer number between -20 and -60 (inclusive). A random floating-point number between 0.0 and 15.9999 (inclusive).

Solution

import java.util.*;

public class Strings {

   public static void main(String[] args)

   {

       Scanner scan = new Scanner(System.in);

       System.out.print(\"Please enter two strings:\");

       String a = scan.next();

       String b = scan.next();

       System.out.println(\"The length of first string is \"+a.length());

       System.out.println(\"The length of second string is \"+b.length());

       if(a==b)

       {

           System.out.println(\"Both the strings are same.\");

       }

       else

       {

           System.out.println(\"Both the strings are different.\");

       }

       System.out.println(\"First string in uppercase is \"+a.toUpperCase());

       System.out.println(\"First string in lowercase is \"+b.toLowerCase());

       if(a.length()==1)

       {

           System.out.println(\"The length of first string must be greater than one to give a substring.\");

       }

       else

       {

           System.out.println(\"Substring of first string is \"+a.substring(0, 2));

       }      

   }

}

 Use Lab 5 practices for guidance to complete the following programs. Required: Use Java assert statement to validate program input values. See Chapter 3 slides
 Use Lab 5 practices for guidance to complete the following programs. Required: Use Java assert statement to validate program input values. See Chapter 3 slides

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site