Question

In: Computer Science

1. For all of the following words, if you move the first letter to the end...

1. For all of the following words, if you move the first letter to the end of the word and then spell the word backwards, you get the original word:

banana dresser grammar potato revive uneven assess

Write a program that gets a word from the keyboard and determines whether it has this property. treat uppercase and lowercase letters alike. That means that poTato also has this property.

2. Write a program that generates a random number (between 1 and 10 inclusive) 100 times. Output the total number of 1s, 2s, ….10s.

Code language is Java. using JGrasp to code

Solutions

Expert Solution

1.

Code:

import java.util.*;  // library file that contains string functions
import java.io.*;  // library file that contains input/output stream reader/writer

// defining class
class main {
        public static void main (String[] args) {
                
                Scanner sc = new Scanner(System.in);
                String word = sc.nextLine();  // taking input
                String word1 = word.substring(0);  // extracting a substring of the word leaving out first letter
                word1 =  word1 + word.charAt(word.length()-1); // adding the extracted substring with 1st letter
                if(word1.equalsIgnoreCase(word)){  // checking condition
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
        }
}
  
        

Output:

2.

Code:

import java.util.*;
import java.io.*;

class main {
        public static void main (String[] args) {
                
                // define the range 
        int max = 10; 
        int min = 1; 
        int range = max - min + 1; 
        int[] arr = new int[11];
  
        // generate random numbers within 1 to 10 
        for (int i = 0; i < 100; i++) { 
            int rand = (int)(Math.random() * range) + min; 
            arr[rand]++;
        }
        for(int i=1; i<11; i++){
            System.out.println("Number of "+i+"'s: "+arr[i]);
        }
        }
}

Output:


Related Solutions

Move all zeros in an arraylist to the end of the list using a temp(java). if...
Move all zeros in an arraylist to the end of the list using a temp(java). if it is an array the code would look like the code below, change it to fit an arraylist int count = 0;     int temp;     for (int i = 0; i < n; i++) {     if ((arr[i] != 0)) {         temp = arr[count];         arr[count] = arr[i];         arr[i] = temp;         count = count + 1;     }     } }
C++ Add a function that finds & displays all the words that begin with the letter...
C++ Add a function that finds & displays all the words that begin with the letter 's'. The text file "dickens.txt" is as follows: It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was...
Answer all the question 1. Electrons like to move it, move it! a. What do we...
Answer all the question 1. Electrons like to move it, move it! a. What do we call reactions that transfer electrons between reactants? b. What does it mean when a substance is oxidized? What does it mean when a substance is reduced? How are oxidation and reduction related? c. What are the two electron carriers found in the process of cellular respiration? d. Ultimately, where do the electron carriers bring electrons to? What is the purpose of moving these electrons?
Respond to the following in a minimum of 175 words: As auditors move from the planning...
Respond to the following in a minimum of 175 words: As auditors move from the planning phase to the fieldwork phase of an audit, they recognize they will not be able to test all transaction in order to offer their opinion on the financial statements. Therefore, various sampling techniques and principles have been developed to assist the auditor in providing adequate coverage and a reliable opinion using samples of transactions. Discuss audit sampling for tests of details of balances and...
Respond to the following in a minimum of 175 words: As auditors move from the planning...
Respond to the following in a minimum of 175 words: As auditors move from the planning phase to the fieldwork phase of an audit, they recognize they will not be able to test all transactions in order to offer their opinion on the financial statements. Therefore, various sampling techniques and principles have been developed to assist the auditor in providing adequate coverage and a reliable opinion using samples of transactions. Discuss audit sampling for tests of details of balances and...
Keys Company showed the following account balances at the end of its first year (assume all...
Keys Company showed the following account balances at the end of its first year (assume all accounts have normal balances):                  Cash                                            $ 2,000 Equipment                                      5,000 Depreciation expense                     3,000 Service Revenue                           18,000 Prepaid insurance                           3,500 Accumulated Depreciation --Equipment                                   2,000 Salaries and Wages expense            5,000 Accounts receivable                        2,500 Accounts payable                            2,000 Rent expense                                  2,500 Notes payable                                 3,000 Common stock                                1,000 Unearned Service Revenue              2,000 Dividends                                           500 Insurance expense                          3,000 Interest expense                             1,000          Net income for the first year is:
______   1.) A Membrane is a boundary that ________ to move across it: Allows all substances...
______   1.) A Membrane is a boundary that ________ to move across it: Allows all substances Does not selectively control which substances Prevents all substances Selectively controls which substances ______   2.) Membrane foundation is formed by the: Chromosomes Enzymes Phospholipids (lipid bilayer) Proteins ______   3.) Lipid bilayer Does permit water soluble substances to pass through it into the cell: False                                             b.) True ______   4.) Fluid Mosaic Model describes the organization of: Cellular membranes Cellular membrane lipids only Cellular membrane proteins...
Match the following descriptions with the appropriate form of learning. 1. You move into a house...
Match the following descriptions with the appropriate form of learning. 1. You move into a house near a train track. At first, you notice trains going by at regular intervals. A few months later a visiting friend asks how often trains pass by. You realize you cannot give an accurate answer because you no longer notice the noise from the trains.  (Click to select)  Classical Conditioning  Operant Conditioning  Habituation 2. You eat some strawberries when you are sick with the flu and subsequently experience...
You failed your classes and you need to write an academic school appeal letter. 200 words
You failed your classes and you need to write an academic school appeal letter. 200 words
Option 1 – the Reference Letter Background You need a reference letter from someone to accompany...
Option 1 – the Reference Letter Background You need a reference letter from someone to accompany a resume and job application. When you ask the referee to write you a letter of reference, they state they would be happy to, but they are very busy. They ask you to draft a letter of reference that they will review, revise, and sign. Your Assignment Draft a 250-word (maximum) reference letter for yourself. Write it as if someone else is writing about...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT