Write code to take two words from the user. The program should convert these to lower case, then compare them: printing a positive number if string1 appears after string2 alphabetically, a negative number if string1 appears before string2 alphabetically and zero if the two strings are identical. Make sure your program does not produce any additional numerical output other than this number or it may not be graded correctly.

Answers

Answer 1

Answer:

Use compareTo.

Explanation:

import java.util.Scanner;

public class U2_L3_Activity_Three{

 public static void main(String[] args){

   Scanner scan = new Scanner(System.in);

   System.out.println("Enter first word: ");

   String word1 = scan.nextLine();

   System.out.println("Enter second word: ");

   String word2 = scan.nextLine();

//I had to make the string all lowercase or all uppercase for when I did this

   word1 = word1.toLowerCase();

   word2 = word2.toLowerCase();

   System.out.println("Result: " + word1.compareTo(word2));

 }

}

Answer 2

Following are the program to converting string value into lowercase and compare with an input string value.

Program Explanation:

Import package.Defining a class Dat.Inside the class defining the main method, and in the method, two string variable "string1, string2" is declared.After input, the value a "toLowerCase" method is used that converts string value into lower case.  After converting value into the lower case a "compareTo" method is used that compares value and prints its value.

Program:

import java.util.*;//import package for input  

public class Dat //defining a Dat

{

public static void main(String[] ax)//main method

{

String string1 ,string2; //defining String variable

Scanner sc = new Scanner(System.in);//creating Scanner class object to input value

System.out.println("Enter values: ");//print message

string1= sc.next();//input value

string2= sc.next();//input value

string1= string1.toLowerCase();//convert string value into LowerCase  

string2 = string2.toLowerCase();//convert string value into LowerCase

System.out.println("Result: " + string1.compareTo(string2));//using compareTo method

}

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/15706308

Write Code To Take Two Words From The User. The Program Should Convert These To Lower Case, Then Compare

Related Questions

I need help Asap!!! So the question is "Compare and contrast Web page and Websites". ​

Answers

Answer:

A website is a mix of web pages while a web page is a single entity.

Explanation:

when working with smart which tab would provide the ability to change the shape or size of the smart art shapes

Answers

It doesn’t change shape

Answer:

B) Format

Explanation:

Methods ii.) Define and implement a method that takes a string array as a parameter and returns the length of the shortest and the longest strings in the array i.) Write a method that take an integer array as a parameter and returns the sum of positive odd numbers and sum of positive even numbers. iii.) Implements the sequential search method that takes and array of integers and the item to be search as parameters and returns true if the item to be searched in the array, return false otherwise

Answers

Answer:

Explanation:

Well I am sorry I don't know the answer anyway.

1, How can technology serve to promote or restrict human rights? [2 points]

Answers

Answer:

Examples of how technology can be used as a powerful tool for human rights are ever expanding. Newer technologies such as artificial intelligence, automation, and blockchain have the potential to make significant positive contributions to the promotion and protection of human rights.

Other Questions
How did the Scientific Revolution influence early industrial development in Britain? If anyone can answer these questions that would help a lot. Besides 13 and 14 please answer the question bellow, i'm so confused lol India receives to types of Monsoons, what are they? * DEF is a right angled triangle calculate the length of EF correct to 3 sigificant figures Jen rode her bike 15of a mile to her friend's house. It took her 5 minutes to get there. What was Jen's speed? Please help ten points Describe what you notice when you create the inverse ratio. I need help with geometry really bad, if you dont mind answering this? And also if your good at geometry drop your number so I can get help Each element... A. Has only one kind of atom B. Has only one kind of molecule C. Is made of rock D. All of the above The price of a television is $567.31. The state sales tax rate is 8.3%.What is the total cost of the television? What is not part of critical thinking?A. Who B. What C. How D. Understand first come first served:) Please help!!!!!!!thank you for helpingggggg The y-intercept is the point where the line crosses theA. originB. slopeC. y-axisD. x-axis In a recent survey of 655 working americans ages 25-34, the average weekly amount spent on lunch was $43.29 with standard deviation $2.75. The weekly amounts are approximately bell-shaped PLEASE can someone find a quote from Educated by Tara Westover with a page number or general chapter that used an allusion, alliteration, or repetition. I will give brainlyist it if you seriously answer!!!! When Ruby practice piano she gets a sticker, and when she does a choreshe gets 2 stickers. When she has 20 stickers her parents will buy her apizza as reward. This system is called? 50 points for answering this question for me and have a bless day The product of the areas of two rectangular rugs is 140. If each of the dimensions is a prime number, what are the four dimensions?A. 2,4,5,7B. 2,2,5,7C. 2,2,5,5D. 2,5,7,7