answer.
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
Maslowich
1 month ago
15

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} java
Computers and Technology
2 answers:
maria [1K]1 month ago
6 0
import java.util.Scanner; public class StoreGuesses { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); final int NUM_GUESSES = 3; int[] userGuesses = new int[NUM_GUESSES]; for (int i = 0; i < NUM_GUESSES; ++i) { userGuesses[i] = scnr.nextInt(); } for (int i = 0; i < NUM_GUESSES; ++i) { System.out.print(userGuesses[i] + " "); } } }
oksian1 [950]1 month ago
3 0

Respuesta:

Para mostrar las adivinanzas numéricas en el arreglo user_guesses, primero es necesario declarar la variable num_guesses y asignarle el valor 3. Luego, se almacenan las adivinanzas en el arreglo user_guesses. Después, se define un ciclo for que itere hasta num_guesses. Finalmente, se imprimen los valores almacenados usando una instrucción de impresión.

Explicación adicional:

A continuación se presenta un programa JAVA que llena el arreglo user_guesses con enteros indicados.

Código:

import java.util.Scanner;

// definición de clase

public class NumberGuesses {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

// inicializar variable num_guesses en 3

final int num_guesses = 3;

// reservar espacio en arreglo para las adivinanzas

int[] user_guesses = new int[num_guesses];

int i = 0;

// declaración del ciclo for

for (i = 0; i < num_guesses; ++i) {

user_guesses[i] = scnr.nextInt();

}

for (i = 0; i < num_guesses; ++i) {

// imprimir resultados

System.out.print(user_guesses[i] + " ");

}

}

return;

}

You might be interested in
Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_
oksian1 [950]
// Below is Java code. // Package import import java.util.*; // class definition class Main { // class main method public static void main (String[] args) throws java.lang.Exception { try{ // variables final int CENTS_PER_POUND = 25; final int FLAT_FEE_CENTS = 75; // Creating Scanner object for input Scanner sr=new Scanner(System.in); System.out.print("Enter the shipping weight:"); // input reading int shipWeightPounds=sr.nextInt(); // cost calculation int shipCostCents = (shipWeightPounds * CENTS_PER_POUND) + FLAT_FEE_CENTS; // output Weight System.out.println("shipping Weight: " + shipWeightPounds); // output flat fee System.out.println("flat fee of shipping in cents: " + FLAT_FEE_CENTS); // output cents per pound System.out.println("Cents/pound for shipping: " + CENTS_PER_POUND); // output shipping cost System.out.println("total cost of shipping in cents: " + shipCostCents); catch(Exception ex){ return;} } } // Explanation: Define two constants "CENTS_PER_POUND=25" and "FLAT_FEE_CENTS=75". Use a Scanner object to capture user input for weight. Calculate the shipping cost by multiplying the weight with cents per pound and adding the flat fee. Then, display each value.
8 0
11 days ago
Read 2 more answers
Given an 10-bit two's complement binary number, what is the decimal value of the largest negative integer that can be represente
Natasha_Volkova [1026]
The largest negative integer is -512.
7 0
10 days ago
c++ 2.30 LAB: Phone number breakdown Given a long long integer representing a 10-digit phone number, output the area code, prefi
oksian1 [950]

Answer:

#include <iostream>

using namespace std;

int main()

{

   // Declare variables to hold entire phone number and its components

   long phone_number;

   int area_code, prefix, line_number;

   cout << "Enter 10-digit phone number:" << endl;

   // Take 10-digit phone number input

   cin >> phone_number;

   // Extract area code, prefix, and line number

   area_code = phone_number / 10000000;

   prefix = (phone_number / 10000) % 1000;

   line_number = phone_number % 10000;

   // Output phone number in desired hyphen-separated format

   cout << area_code << "-" << prefix << "-" << line_number << endl;

   return 0;

}

Output:

Enter 10-digit phone number:

8005551212

800-555-1212

Explanation:

The program takes a 10-digit phone number input from the user and stores it in the variable phone_number.

Using division and modulus operations, it separates the phone number into three parts:

area_code = phone_number / 10000000;

prefix = (phone_number / 10000) % 1000;

line_number = phone_number % 10000;

Finally, the program prints these parts joined by hyphens.

5 0
1 month ago
Would two bits be enough to assign a unique binary number to each vowel in the English language? Explain.
Harlamova29_29 [1022]

Response:

No.

Clarification:

Since there are 5 vowels, at least 3 bits are necessary to represent them all. Utilizing 2 bits yields 2²=4 combinations, which isn’t enough. However, using 3 bits provides 2³=8 combinations, sufficiently covering the 5 vowels.

3 0
1 month ago
Jacob wants to be a Steamfitter. He just finished his associate’s degree. Which best describes what he should do next?
8_murik_8 [964]
He should pursue a bachelor's degree next. I am also taking the test and choosing option A. 
8 0
29 days ago
Read 2 more answers
Other questions:
  • While trying to solve a network issue, a technician made multiple changes to the current router configuration file. The changes
    7·1 answer
  • Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
    12·1 answer
  • 7. Which of these statements is true? Agile is a programming language MySQL is a database HTML stands for "Hypertext Markup Link
    15·1 answer
  • To what extent are the following computer systems instances of artificial intelligence:
    14·1 answer
  • A client is currently struggling with late-stage integration and manual deployments. They want to find another method that will
    5·1 answer
  • SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the classes listed in the Java Quick R
    9·1 answer
  • More Loops: All versions of foods.py in this section have avoided using for loops when printing to save space. Choose a version
    13·1 answer
  • As part of the duties of a digital forensics examiner, creating an investigation plan is a standard practice. Write a 3 to 4 (no
    9·1 answer
  • A ____ partition contains the data necessary to restore a hard drive back to its state at the time the computer was purchased an
    8·2 answers
  • During which stage does the central processing unit analyze the instruction and encode it in the form of a number, and then gene
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!