Question

In: Computer Science

Set hasDigit to true if the 3-character passCode contains a digit. public class CheckingPasscodes { public...

Set hasDigit to true if the 3-character passCode contains a digit.

public class CheckingPasscodes {

public static void main (String [] args) {

boolean hasDigit = false;

String passCode = "";

int valid = 0;

passCode = "abc";

/* Your solution goes here */

if (hasDigit) {

System.out.println("Has a digit.");

}

else {

System.out.println("Has no digit.");

}

return;

}

}

Solutions

Expert Solution

Program:

Sample output:

if passCode = "ab3";

Code to copy:

public class CheckingPasscodes

{

     public static void main (String [] args)

     {

          boolean hasDigit = false;

          String passCode = "";

          int valid = 0;

          passCode = "abc";

          //check each character in the passcode whether

          //the passcode has a digit or not

          for(int index = 0;index < passCode.length();index++)

          {

              char charcter=passCode.charAt(index);

              //check the character is a digit or not

              if(Character.isDigit(charcter))

              {

                   //set the boolean value hasDigit as true, if

                   // the character is a digit

                   hasDigit = true;

              }

          }

          //display a message "Has a Digit, if the passcode

          //contains a digit

          if (hasDigit)

          {

              System.out.println("Has a digit.");

          }

          //display a message "Has no digit, if the passcode

          //does not contain a digit

          else

          {

              System.out.println("Has no digit.");

          }

          return;

     }

}


Related Solutions

(In C)Set hasDigit to true if the 3-character passCode contains a digit.
  Set hasDigit to true if the 3-character passCode contains a digit. (in C) #include <stdio.h> #include <string.h> #include <stdbool.h> #include <ctype.h>   int main(void) { bool hasDigit; char passCode[50]; hasDigit = false; scanf("%s", passCode); /* Your solution goes here */ if (hasDigit) { printf("Has a digit.\n"); } else { printf("Has no digit.\n"); } return 0; }
(C++)Set hasDigit to true if the 3-character passCode contains a digit.
C++. Set hasDigit to true if the 3-character passCode contains a digit. #include #include #include using namespace std; int main() {bool hasDigit;string passCode; hasDigit = false;cin >> passCode; /* Your solution goes here */ if (hasDigit) {cout
(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.");}}}
(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();     ...
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should...
Instructions: In this exercise, you’ll design a role playing character class. The Character class attributes should include the characters’s name, gender, class* and race (can be human, elf or dwarf), and additional integer attributes of Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma. Your class should have a constructor that receives this data. For each attribute, provide setters and getters. The class should include methods that calculate and return the user’s total attributes (sums 6 attributes). Write a Java application that prompts...
import java.util.*;    public class DataAnalysis{    static Set<String> Data_NaN(Set<String> set){        Set<String> set2 =...
import java.util.*;    public class DataAnalysis{    static Set<String> Data_NaN(Set<String> set){        Set<String> set2 = new HashSet<String>();    for (String temp : set) {        temp = temp.replaceAll(        "[^0-9]", "");                  if(!(set.isEmpty())){            set2.add(temp);        }    }    return set2;               } public static void main(String args[]) { // create empty set Set<String> set = new HashSet<String>(); // {3, 25, 33, 21, 55, 43, 78,...
a. How many 3-digit numbers can you make using the digits from the set of (3,...
a. How many 3-digit numbers can you make using the digits from the set of (3, 4, 5, 6, 8, 2, 7) without repetitions? b. How many numbers can be made with the digits from the set of (0, 3, 5, 7, 8, 4, 9), which are greater than 0 and less than a thousand (repetitions are allowed)?
public class Graph { private ST<String, SET<String>> st; public Graph() { st = new ST<String, SET<String>>();...
public class Graph { private ST<String, SET<String>> st; public Graph() { st = new ST<String, SET<String>>(); } public void addEdge(String v, String w) { // Put v in w's SET and w in v's SET. if (!st.contains(v)) st.put(v, new SET<String>()); if (!st.contains(w)) st.put(w, new SET<String>()); st.get(v).add(w); st.get(w).add(v); } public Iterable<String> adjacentTo(String v) { return st.get(v); } public Iterable<String> vertices() { return st.keys(); } // See Exercises 4.5.1-4 for V(), E(), degree(), // hasVertex(), and hasEdge(). public static void main(String[] args)...
3) Which of the following statements is true or false a) Character displacement occurs when two...
3) Which of the following statements is true or false a) Character displacement occurs when two species using the same resource overlap in their distributions and become more similar to each other than they are where they don’t overlap. b) If you wanted to know if an organism which expresses a dominant phenotype is homozygous or heterozygous for a trait (e.g., round pea shape, R_), you could do a “test cross” between the unknown individual (R_) and an individual which...
Question 4: Set P to the largest digit in your 5 digit number. For example, if...
Question 4: Set P to the largest digit in your 5 digit number. For example, if your 5 digit number is 88412, then P should be set to 8. Calculate and print the value of (P+1) multiplied by itself (P+3) times. As an example, if your 5 digit number is 88412, you should print the result of multiplying 9 with itself 12 times -- this is also known as 9 to the power of 12. HINT: you are free to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT