Write an expression to detect that the first character of userinput matches firstletter.


Asked by wiki @ in Computers And Technology viewed by 736 People


1 import java.util.Scanner; 3 public class CharMatching 4 public static void main (String [] args) { Scanner scnr new Scanner(System.in); String userInput; char firstLetter; userInput = scnr.nextLine(); firstLetter scnr.nextLine().charAt (0); 12 13 14 15 if (/* Your solution goes here * System.out.printin( "Found match: "firstLetter); else t System.out.println("No match: " firstLetter); 17 18 19 20 21 return

Answered by wiki @


Answer:

The code to this question as follows:

Code:

if(userInput.charAt(0)==firstLetter) // if block

{

//statements

}

else //else block

{

//statements.

}

Explanation:

The description of the above code as follows:

  • In the program, we use two variables for user input that is "userInput and firstLetter". The datatype of the userInput is a string that is used to insert any value from the user. Then we use the firstLetter variable the datatype of the variable is char because it is used to detect first character. To detect this we define the conditional statement.
  • In the if block we check condition that userInput first index value is equal to firstLetter it will print "Found match: value".
  • In else block if the value does not match it will print "No match: value".

Similar Questions

Write words to match the expression 3 4 12

Asked by maham237 @ in Mathematics viewed by 354 persons

Write words to match expression 3+(4x12)

Write the mathematical expression for first law of thermodynamics

Asked by admin @ in Physics viewed by 302 persons

state first law of thermodynamics.give its mathematical expression. name the physical quantity defined by first law of thermodynamics.

State first law of thermodynamics. write its mathematical expression

Asked by admin @ in Physics viewed by 326 persons

state first law of thermodynamics.give its mathematical expression. name the physical quantity defined by first law of thermodynamics.

State first law of thermodynamics. write its mathematical expression.

Asked by admin @ in Physics viewed by 448 persons

state first law of thermodynamics.give its mathematical expression. name the physical quantity defined by first law of thermodynamics.

What does anne write in her first essay

Asked by admin @ in English viewed by 337 persons

Why does anne write in her first essay

Derive the mathematical expression for first law of thermodynamics

Asked by admin @ in Physics viewed by 330 persons

Derive first law of thermodynamics mathematically

A character which is expressed in hybrid is called

Asked by admin @ in Biology viewed by 280 persons

A character which is expressed in a hybrid is called A. Dominant B. Recessive C. Co-dominant D. Epistatic

When was the first cricket test match played 1873

Asked by admin @ in English viewed by 343 persons

When was the first cricket test match played A) 1873 B) 1877 C) 1870 D) 1788

Who was the first character to speak in star wars

Asked by admin @ in Sociology viewed by 278 persons

Who was the first character to speak in Star Wars?​

Match the expression with its name 3x 3 3x 3

Asked by maham237 @ in Mathematics viewed by 374 persons

not a polynomial fourth-degree monomial quadratic binomial cubic trinomial

Write an expression that is equal to 3x2 1 4

Asked by maham237 @ in Mathematics viewed by 473 persons

3x2 1/4

How to find first character in a string in java

Asked by admin @ in Computers and Technology viewed by 342 persons

Write an expression to detect that the first character of userinput matches firstLetter. 1 import java.util.Scanner; 3 public class CharMatching 4 public static void main (String [] args) { Scanner …

Against whom did india play its first cricket match

Asked by admin @ in English viewed by 336 persons

Against Whom did India Play its first Cricket Match ?

Write a diary entry on my first day in school

Asked by admin @ in English viewed by 535 persons

Write a diary entry on my first day at my new school for class 5

Match the meaning of each of the following expressions

Asked by maham237 @ in Mathematics viewed by 313 persons

Match the meaning of each of the following expressions. 1. the sum of n and five x - (8 + 2) 2. five subtracted from n x - 8 3. …

Most viewed questions in Computers And Technology


Codehs python answer key

Asked by maham237 @ in Computers And Technology viewed by 2076 persons


3.4 6 t shirt shop codehs answers

Asked by maham237 @ in Computers And Technology viewed by 1846 persons



Security infrastructure design document

Asked by wiki @ in Computers And Technology viewed by 1797 persons


Codehs python answers

Asked by maham237 @ in Computers And Technology viewed by 1161 persons


In the business world people are often measured by their

Asked by maham237 @ in Computers And Technology viewed by 1096 persons




Banana fee fi fo fana song

Asked by maham237 @ in Computers And Technology viewed by 791 persons


List 10 www standards that the w3c develops and maintains

Asked by maham237 @ in Computers And Technology viewed by 778 persons


Open the excel workbook revenue xls from the default directory

Asked by maham237 @ in Computers And Technology viewed by 742 persons



In order to protect your computer from the newest viruses

Asked by maham237 @ in Computers And Technology viewed by 736 persons