1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
a_sh-v [17]
3 years ago
5

HELP ME WITH JAVA: This is my assignment. I need to write a program with a main method and methods. Use a scanner to get the Str

ing from the user. I am lost.
DON'T USE THE FOLLOWING IN THE PROGRAM:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

Computers and Technology
1 answer:
viva [34]3 years ago
4 0

Here you go. I did not see the need to create a separate class to return one string character to an array index, since I only have to make that conversion once, where I increment the array value (the part with  [c-'a']).

The user can terminate the program by pressing enter, ie., enter an empty string.


import java.util.Scanner;



public class Analyzer  

{    

  public static void Analyze(String line)  

  {  

       int[] histogram = new int[26];


       for(int i=0; i<line.length(); i++) {


           char c = Character.toLowerCase(line.charAt(i));


           if ((c >='a' && c <= 'z')) {


               histogram[c-'a']++;


           }


       }


       for(int i=0; i<26; i++) {


           if (histogram[i] > 0) {


              System.out.format("%c: %d times.\n", 'a'+i, histogram[i]);  

           }            


       }


  }  



   

  public static void main(String[] args)  

  {      


       String line = "";


       Scanner scan = new Scanner(System.in);


       do {


           System.out.print("Enter a string: ");


           line = scan.nextLine();


           if (line.length()>0) {


               Analyze(line);


           }


       } while (line.length() > 0);


  }


}

You might be interested in
The following code accomplishes which of the tasks written below? Assume list is an int array that stores positive int values on
liq [111]

Answer:

It stores the largest value in list (the maximum) in the variable 'foo'.

Explanation:

<u>Following are the description of the answer</u>:

In the above code, they set and initialize the integer data type variable that is 'foo' to 0. Then, they set the for loop that iterates from 0 and end at length of the list. Then, they check the condition, if the list of j i.e., list[j] is greater than the variable 'foo', then the value of the list[j] stored in the variable 'foo'.

So, if the value of the list[j] is greater than 0, then the value of the list[j] is initialized in the variable 'foo'. That's why it stores the largest value.

6 0
3 years ago
A corporation needs an operating system that allows the various teams in its office to network and collaborate on projects. Whic
Nikolay [14]
This totally depends on what they need and what they are willing to spend. If they just need access to google docs/ sheets etc for example (so just the web with a web browser), either Linux / Un*x or Windows will do and linux is the free choice. If they want to be part of the microsoft ecosystem or use some windows specific software they will need to use Windows or an emulator in Linux.

I would not recommend MSDOS in this day and age.
7 0
3 years ago
Read 2 more answers
The school has determined that finding the absolute best schedule cannot be solved in a reasonable time. Instead they have decid
Anettt [7]

Answer:

i dont know what to say

Explanation:

... speechlessss

4 0
3 years ago
What was the name of the first personal computer and what year was it introduced
Nadya [2.5K]

Answer:

IBM's own Personal Computer (IBM 5150) was introduced in August 1981, only a year after corporate executives gave the go-ahead to Bill Lowe, the lab director in the company's Boca Raton, Fla., facilities. He set up a task force that developed the proposal for the first IBM PC.

6 0
2 years ago
What do you call a collection of pre-programmed commands and functions used in programs?
densk [106]
The answer is number 3.libary
5 0
3 years ago
Other questions:
  • What year did buck tooth bob become famous
    11·2 answers
  • In a certain computation, 90% of the work is vectorizable. Of the remaining 10%, half is parallelizable for an MIMD machine. Wha
    9·1 answer
  • What are ways to enter formula in Excel? Check all that apply
    8·2 answers
  • Which operating system is a version of Linux?​
    13·1 answer
  • Q.drtrdyudoijoemrkdf
    6·2 answers
  • Energía de movimiento de los átomos o moléculas
    11·1 answer
  • select the correct answer from each drop-down menu. “To clean a computer screen, use ___. To clean a keyboard, use a ___.”
    7·1 answer
  • How to prepare and draw a corresponding flowchart to compute the sum and product of all prime numbers between 1 and 50
    7·1 answer
  • 16. The Nintendo Entertainment System (NES) saw its sales skyrocket as a result of the launch of which of the following games?
    14·1 answer
  • Select the correct answer from each drop-down menu. What is a distribution list and how is it selected?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!