Question

In: Computer Science

(In JAVA)Write code to print the location of any alphabetic character in the 2-character string passCode.

Java Language

Write code to print the location of any alphabetic character in the 2-character string passCode. Each alphabetic character detected should print a separate statement followed by a newline. Ex: If passCode is "9a", output is:

Alphabetic at 1

import java.util.Scanner;

 

public class FindAlpha {

   public static void main (String [] args) {

      Scanner scnr = new Scanner(System.in);

      String passCode;

      

      passCode = scnr.next();

      

      /* Your solution goes here */

      

   }

}

Solutions

Expert Solution

import java.util.Scanner;

public class FindAlpha {

   public static void main (String [] args) {

      Scanner scnr = new Scanner(System.in);

      String passCode;

      passCode = scnr.next();

      /* Your solution goes here */

      if(Character.isLetter(passCode.charAt(0))) {    //As it 2-character passcode we can check characters at    0 and 1

         System.out.println("Alphabetic at 0"); //isLetter() is used to check whether ch is alphabet or not

      }

      if(Character.isLetter(passCode.charAt(1))) {

         System.out.println("Alphabetic at 1");

      }

   }

}

 

OutPut:

Related Solutions

(JAVA)Set hasDigit to true if the 3-character passCode contains a digit.
JAVE 3.10.1: String with digit. Set hasDigit to true if the 3-character passcode contains a digit. MUST USE THIS TEMPLATE: public class CheckingPasscodes {public static void main (String [] args) {boolean hasDigit;String passCode; hasDigit = false;passCode = "abc"; /* Your solution goes here */ if (hasDigit) {System.out.println("Has a digit.");}else {System.out.println("Has no digit.");}}}
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
To begin, write a program to loop through a string character by character. If the character...
To begin, write a program to loop through a string character by character. If the character is a letter, print a question mark, otherwise print the character. Use the code below for the message string. This will be the first string that you will decode. Use the String class method .charAt(index) and the Character class method .isLetter(char). (You can cut and paste this line into your program.) String msg = "FIG PKWC OIE GJJCDVKLC MCVDFJEHIY BIDRHYO.\n"; String decryptKey = "QWERTYUIOPASDFGHJKLZXCVBNM";...
Please write code in java and comment . thanksItem classA constructor, with a String...
Please write code in java and comment . thanksItem classA constructor, with a String parameter representing the name of the item.A name() method and a toString() method, both of which are identical and which return the name of the item.BadAmountException ClassIt must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it.It must have a default constructor.It must have a constructor which...
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced.
Write Java code that prompts the user for a string and tells them if the grouping characters in that string are balanced. Grouping characters are ( and ), [ and ], and { and }. I got the basic idea for this problem from HackerRank. It’s also a very common interview question.*******************8Example output**************Enter the expression:{[()]} {[()]}is balancedEnter the expression: {()()} {()()}is balancedEnter the expression: {([[])} {([[])}is not balancedEnter the expression: {([)]} {([)]}is not balanced
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
Please write code in java and comment . thanks Item class A constructor, with a String...
Please write code in java and comment . thanks Item class A constructor, with a String parameter representing the name of the item. A name() method and a toString() method, both of which are identical and which return the name of the item. BadAmountException Class It must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it. It must have a default...
Write a java code segment to declare an array of size 10 of type String and...
Write a java code segment to declare an array of size 10 of type String and read data for them from a file, prompt user for the file name. Data is stored in a file with 1 string per line.
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
How To Print Nice Padding Character in a String in C++? 1. User input the width...
How To Print Nice Padding Character in a String in C++? 1. User input the width = 14 2. User input the padding character = + Example output: ++Hello World++ Thanks in advance.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT