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
Serhud [2]
3 years ago
8

Write a for loop to populate array userGuesses with NUM_GUESSES integers. Read integers using Scanner. Ex: If NUM_GUESSES is 3 a

nd user enters 9 5 2, then userGuesses is {9, 5, 2}.
Computers and Technology
1 answer:
Tema [17]3 years ago
5 0

Answer:

import java.util.Arrays;

import java.util.Scanner;

public class num12 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter Number of guesses");

       int NUM_GUESSES = in.nextInt();

       int [] userGuesses = new int[NUM_GUESSES];

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

           System.out.println("Enter each value");

           userGuesses[i]= in.nextInt();

       }

       System.out.println("userGuesses is "+ Arrays.toString(userGuesses));

   }

}

Explanation:

  • Prompt user to enter a value for the length of the array int NUM_GUESSES = in.nextInt();
  • Create an array of int int [] userGuesses = new int[NUM_GUESSES];
  • Use a for loop to request and add elements to the array
  • print the array using Arrays.toString () method
You might be interested in
Write a Java program that will 1. Ask the user to type in a sentence, using a JOptionPane.showInputDialog(). 2. The program will
Paraphin [41]

Answer:

Here is the JAVA program :

import javax.swing.JOptionPane;   //to use JOptionPane  

public class Main {   //class name

public static void main(String[] args) { //start of main method

   int ECount= 0;   //counts number of upper case E

   int eCount= 0;  //counts number of lower case e

   String sentence;   //stores input sentence string

sentence = JOptionPane.showInputDialog(null, "Type a sentence (type stop to exit)");  //uses showInputDialog method to display a dialog box which prompts user to enter a sentence

 int length = sentence.length();  //stores the length of the sentence

 while (!sentence.equalsIgnoreCase("stop"))  //the loop continues to execute until the user types stop

{ for (int i = 0; i < length; i++) { //loops through the sentence

             if (sentence.charAt(i) == 'E')  //if the character is an uppercase E

                  ECount += 1;  //adds 1 to the count of Ecount

             if (sentence.charAt(i) == 'e')  //if the character in a sentence is lowercase e

                  eCount += 1;}  //adds 1 to the count of lower case e

JOptionPane.showMessageDialog(null, "There are " + ECount + " number of E's and " + eCount + "  number of e's in " +sentence);   //displays the number of times uppercase and lowercase (E and e) occur in sentence

sentence = JOptionPane.showInputDialog(null, "Type a sentence (type stop to exit");  //prompts user to enter the next sentence

length = sentence.length();  //stores the length of sentence at each iteration of while loop until user enters stop

eCount=0;  //resets the counter of lowercase e

ECount=0;  } } } //resets the counter of uppercase e

Explanation:

The program uses showInputDialog() method that displays a dialog box on output screen. This dialog box prompts the user to enter a string (sentence) Suppose user enters "Evergreen" as input sentence so

sentence = "Evergreen"

Next the length of this string is computed using length() method and stored in length variable. So

length = sentence.length();

length = 9

The for loop iterates through this input sentence until the variable i is less than length i.e. 9

At first iteration

if (sentence.charAt(i) == 'E') becomes

if (sentence.charAt(0) == 'E')

Here charAt() method is used which returns the character at the specified index i. This if condition is true because the character at 0-th index (first character) of the sentence Evergreen is E. So ECount += 1; statement adds 1 to the count of upper case E so

ECount = 1

At second iteration:

if (sentence.charAt(1) == 'E')

this condition is false because the character at 1st index of sentence is 'v' which not an upper case E so the program moves to next if condition if (sentence.charAt(i) == 'e') which is also false because the character is not a lower case e either.

At third iteration:

if (sentence.charAt(2) == 'E')

this condition is false because the character at 2nd index of sentence is 'e' which not an upper case E so the program moves to next if condition if (sentence.charAt(i) == 'e') which is true because the character is a lower case e. So the statement eCount += 1; executes which adds 1 to the count of e.

eCount = 1

So at each iteration the sentence is checked for an upper case E and lower case e. After the loop breaks, the program moves to the statement:

JOptionPane.showMessageDialog(null, "There are " + ECount + " number of E's and " + eCount + "  number of e's in " +sentence);

which displays the number of uppercase E and lower case e in a message dialog box. So the output is:

There are 1 number of E's and 3 number of e's in Evergreen.

Then because of while loop user is prompted again to enter a sentence until the user enters "stop". Now the user can enter Stop, StOp, STOp etc. So equalsIgnoreCase method is used to cover all upper/lower case possibilities of the word "stop".

The screenshot of the program and its output is attached.

6 0
4 years ago
Consider the following class: public class Dog { private String name; private String breed; public String getName() { return nam
OLga [1]

Answer:

Name of dog specified in constructor i.e. Karel.

Explanation:

5 0
4 years ago
In the 2000s, Venezuelan President Hugo Chàvez instituted economic policies that caused smuggling and hoarding of food. What did
icang [17]
Chavez set a price ceiling on food. This is represented by the letter C - A price ceiling is a control or limit imposed by a government over how high a price can be charged for a product. By doing this, Hugo Chavez made a huge blunder, since it resulted in the quantity of food demanded exceeding the quantity supplied. This in turn resulted in people smuggling and hoarding food.
7 0
4 years ago
This software application can be used to organize, analyze, and illustrate data?
valkas [14]

Answer:

Excel

Explanation:

Excel is a program by Microsoft that allows the user to create and organize data in tables in graphs.

Word is a documentation program by Microsoft that allows the user to create a written document with images, graphs, etc. But it is not used to organize data.

PowerPoint is a program by Microsoft that allows the user to create and display presentations.

Outlook is a program by Microsoft the allows the user to email other users' and emails along with other emails in general.

7 0
3 years ago
Read 2 more answers
Number of frames displayed per second
Oksi-84 [34.3K]

Are you looking for the abbreviation if so it is FPS

5 0
4 years ago
Other questions:
  • g c 24-hour time (also known in the U.S. as military time) is widely used around the world. Time is expressed as hours since mid
    7·1 answer
  • What is wrong with the following code? How should it be fixed?
    12·1 answer
  • Cell phones replacing fixed line phones is an example of:
    12·1 answer
  • What happens when the data in an investigation does not support the original hypothesis? The scientist gives up and starts an in
    10·2 answers
  • Considering the concept of salted passwords, answer the following questions: a. Bob thinks that generating and storing a random
    10·1 answer
  • James would like to send a document he has saved on the hard drive to coworkers in Ireland, Brazil, and India. These coworkers h
    6·2 answers
  • Write a program that computes how much each person in a group needs to pay (after tax and tip) when splitting the bill equally.
    5·1 answer
  • HELLO. Which of the following is NOT a way to control the flow of a program?
    6·2 answers
  • 9) Which date is assigned the serial number of 1?
    10·2 answers
  • Write a python program to check whether the number is divisible by 7. If its divisible, print its divisible otherwise find previ
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!