Write a program that asks the user to enter 2 words, then prints "Great!" if the two words are identical, "Close enough" if they are the same length and all but the last letter matches, and "Try again" otherwise.

java, desperate fr

Answers

Answer 1

Answer:

 System.out.println("Enter 2 strings:");

   Scanner scan = new Scanner(System.in);

   String a = scan.nextLine();

   String b = scan.nextLine();

   int c = a.length();

   int d = b.length();

   String e =  a.substring(0, a.length()-1);

   String f = b.substring(0, b.length()-1);

   if (a.equals(b)){

     System.out.println("Great!");

   }

   else if (c== d && e.equals(f)){

     System.out.println("Close enough");

   }

   else{

     System.out.println("Try again");

   }

 }

 

}

Explanation:

Answer 2

Following are the java program to comparing the words:

Program Explanation:

Import package.Defining the main class.Defining the main method.Inside the main method two string "f,s" is declared that uses input method to input value.After input value multiple conditional statement is declared that checks inputs value.In the if block, it checks first string value equal to second value, if it is true it will print a message "Great!".In the else if block it checks string value that has same length, for this it uses "l" variable that checks length value, and the print the message "Close enough".In the else block, it will print the message "Try again".

Program:

import java.util.*;//import package public class Main //defining a class {    public static void main(String[] ars) //defining main method    {        String f,s;//defining String variable        Scanner obc=new Scanner(System.in);//creating Scanner class object        System.out.print("Enter First word: ");//print message        f=obc.next();//input value        System.out.print("Enter Second word: ");//print message        s=obc.next();//input value        if(f.equals(s))//use if to check input string value are equal            System.out.println("Great!");//print message        else if(f.length()==s.length())//using else if block that checks string value has same length         {            int c=0;//defining integer variable             int l=f.length();//defining integer variable l that holds first string length value            for(int i=0;i<l;i++) //using for loop to compare string value            {                if(f.charAt(i)==s.charAt(i))//use if to compare string by using charAt method                    c++;//incrementing c value            }            if(c==l-1 && f.charAt(l-1)!=s.charAt(l-1)) //comparing string            {                System.out.println("Close enough");//print message            }        }        else //defining else        {            System.out.println("Try again");//print message        }    } }

Output:

Please find the attached file.

Learn more:

brainly.com/question/20875119

bvbmb

Write A Program That Asks The User To Enter 2 Words, Then Prints "Great!" If The Two Words Are Identical,

Related Questions

what are output devices ?
name them​

Answers

Answer:

Monitor.

Printer.

Headphones.

Computer Speakers.

Projector.

GPS.

Sound Card.

Video Card.

Explanation:

Before inserting a cover page or a blank page, where should the cursor be placed?
O at the end of the first line on the page to insert the new page after it
at the end of the last line on the page to insert the new page before it
at the beginning of the last line on the page to insert the new page after it
O at the beginning of the first line on the page to insert the new page before it

Answers

Answer:

At the beginning of the first line on a page to insert the new page before.

Explanation:

if you need more assistance please let me know.

cheers

Answer:

D.  at the beginning of the first line on the page to insert the new page before it

Explanation:

Other Questions
Screenshot very easy ***Answer when you can!***Evaluate functions from their graph g(-4)=?? pls help :( plssss plsss pls What is a half-life of an isotope? please help What is the twisted ladder shape of the DNA called?:3-D model:nucleotides:double helix:single strand Pi times 2444.57 divided by 344.5=? Which of these is a chemical property used to identify minerals?O A. ReactivityO B. ColorO C. LusterO D. Hardness . What units would you use to measure a red blood cell?1. Nanometers2. micrometers3. millimeters Write a equation in slope-intercept form of the line that passes though (-5,19) and (5,13) Find the value of x. Then, find the measure of each labelled angle. x=_(7x+10)=_(15x+16)=_ BRAINLIEST ON THE LINE INFO IN PHOTO BELOW All of the points in the picture are on the same line.YA(6, 10)(a, 8)(4,5)(2, 2)1. Find the slope of the line. Explain or show your reasoning,2. Write an equation for the line.3. Find the values for a and b. Explain or show your reasoning4. What is the y-coordinate when x = 0? Explain or show your reasoning. What did Mrs. Baker say when she read the note from Mr. Guareschi after Hollingcame back from the office? The First-person to get correct will get BRAINLESIT I think of a number, multiply it by four, and subtract three. I get eleven. a) Using the statement above, form an equation. Use the letter 'x' for the unknown number.b) Solve the equation The monthly payment for a car lease is $530 for 18 months. The down payment is $2,000. The residual value is $7,000. What is the total cost of the lease? A. $18,540 B. $20,540 C. $25,540 Developments such as the one depicted in the painting most directly contributed to which of the following in Afro-Eurasia in the fourteenth and fifteenth centuries? Which effects would many organisms likely experience if global warming occours check all that applyDisrupted food webs Increased competition Increased number of glaciers Disrupted life cycle eventsForced relocation what is this !?help please! I am less than 10 l am not a multiple of 2 l am a composite number. Why is it important to know the weather?