Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program thet uses the function strcmp() to compare two strings input by

ID: 3683820 • Letter: W

Question

Write a program thet uses the function strcmp() to compare two strings input by the user. The program should state whether the first string is less then, equal to, or greater then the second string 7. Write a program thet uses the function strcmp() to compare two strings input by the user. The program should state whether the first string is less then, equal to, or greater then the second string

Explanation / Answer

import java.util.Scanner; class CompareStrings { public static void main(String args[]) { String s1, s2; Scanner in = new Scanner(System.in); System.out.println("Enter the first string"); s1 = in.nextLine(); System.out.println("Enter the second string"); s2 = in.nextLine(); if ( s1.strcmp(s2) > 0 ) System.out.println("First string is greater than second."); else if ( s1.strcmp(s2) < 0 ) System.out.println("First string is smaller than second."); else System.out.println("Both strings are equal."); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote