Question

How can i compare a string to a list of known words (add, load, store, r0,...

How can i compare a string to a list of known words (add, load, store, r0, r1, r2) in Java

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String arr[] = {"add", "load", "store", "r0", "r1", "r2"};
    String word = "store";
    boolean flag = false;
    for(String w: arr){
      if(word.equals(w)){
        flag = true;
      }
    }
    if(flag){
      System.out.println(word+" found");
    }
    else {
      System.out.println(word+" NOT found");
    }
  }
}

store found

Add a comment
Know the answer?
Add Answer to:
How can i compare a string to a list of known words (add, load, store, r0,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following operations: A B- C The corresponding assembly code instruction list generated by a compiler are 1 load [%r0 +4], %r1 2 load [%r0 + 8], %r2 3 sub %r1, %r2,%r3 4 load [ZrO + 1...

    Consider the following operations: A B- C The corresponding assembly code instruction list generated by a compiler are 1 load [%r0 +4], %r1 2 load [%r0 + 8], %r2 3 sub %r1, %r2,%r3 4 load [ZrO + 12], %r4 5 add %r3, %r4 , %r5 6 store %r3, [%r0 + 16] 7 store %r5, [%r0 + 20] a) Identify the potential pipeline hazards. (10 points) b) State if the found hazards can be eliminated and if so propose a scheme...

  • I have to convert an assembly program into java. The code is as follows: LOAD R1,...

    I have to convert an assembly program into java. The code is as follows: LOAD R1, = 0 LOAD R2, =0 LOAD R3, =10 LOOP: ADD R1, R2 INC R2 BLT R2, R3, LOOP HALT

  • Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of...

    Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of lower case to upper is provided below: Let’s look at a subroutine to capitalize all the lower-case letters in the string. We need to load each character, check to see if it is a letter, and if so, capitalize it. Each character in the string is represented with its ASCII code. For example, ‘A’ is represented with a 65 (0x41), ‘B’ with 66 (0x42),...

  • How can I sort a string array? I have the array String [] words = {apple,...

    How can I sort a string array? I have the array String [] words = {apple, null, banana, orange}; which needs to be sorted to be "apple, banana, orange, null." How do I sort so the strings are all on the left, and null is on the right?

  • If i have a node list type string, how do i put the data from each...

    If i have a node list type string, how do i put the data from each node into a string array and print the results? I am creating the node list myself so i just need generic code how to print the data from each node into a String array. 1670 * 168 * Returns an array of the words in the list, in the order that the client * would expect. * * 169 170 171 172 * *...

  • Analysis In java, a List can be implemented in a number of ways. Compare and contrast...

    Analysis In java, a List can be implemented in a number of ways. Compare and contrast an ArrayList and a LinkedLists. In which situations would you use one to implement a List over another? (explain in runtime on add and remove, memory usage, and get/set.)

  • How do remove an object from list and add to another with indexes (java) Ex: I...

    How do remove an object from list and add to another with indexes (java) Ex: I have two separate list classes, Dogs and WalkedDogs, so once a dog from the Dog list has been walked, I want to remove that dog from the Dog list and at the same time then add it to the WalkedDogs list. By doing so via ui, so when main runs, the user is shown a list of Dogs, and chooses a dog with index...

  • Part I. Representation of a String The primitive type char is used to store a single...

    Part I. Representation of a String The primitive type char is used to store a single character, whether it is a letter, number or special character (for example: space, tab, or new line). More often, we want to store a string of characters in a single variable. We can do this by using a variable of the class type String. A String variable can be initialized to a String literal (which is similar to how a char variable can be...

  • IN JAVA PLEASE Lab 28.1 Add a class named Purchase with: an instance (String) variable for...

    IN JAVA PLEASE Lab 28.1 Add a class named Purchase with: an instance (String) variable for the customer's name an instance (double) variable for the customer's balance a member method public String toString() that returns the object's instance variable data as a single String; e.g., Cathy has a balance of $100.00 Lab 28.2 Add a main class named Store; . Then, add code that: declares and creates an ArrayList of Purchase objects named purchases (make sure to add import java.util.ArrayList...

  • I need to add something to this C++ program.Additionally I want it to remove 10 words...

    I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words);    int main() { // Declaring variables std::map<std::string,int> words;       //defines an input stream for the data file ifstream dataIn;    string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT