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
gizmo_the_mogwai [7]
3 years ago
15

Debug the code in the main method of this class, which is intended to initialize an array named arr to hold 3 ints, fill this wi

th 3 inputs from the user, then print the contents of the array in order followed by the sum.
Here's the code that needs to be fixed:

import java.util.Scanner;

public class U6_L1_Activity_One{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int[] arr = new int(3);
arr[1] = scan.nextInt();
arr[2] = scan.nextInt();
arr[3] = scan.nextInt;
System.out.println("Contents: " + arr{1} + " " + arr{2} + " " + arr{3});
System.out.println("Sum: " + arr[1] + arr[2] + arr[3]);
}
}
Computers and Technology
1 answer:
pentagon [3]3 years ago
5 0

Answer:

import java.util.Scanner;

public class U6_L1_Activity_One{

 public static void main(String[] args){

   Scanner scan = new Scanner(System.in);

   int[] arr = new int[4];

   arr[1] = scan.nextInt();

   arr[2] = scan.nextInt();

   arr[3] = scan.nextInt();

   System.out.println("Contents: " + arr[1] + " " + arr[2] + " " + arr[3]);

   int Sum = (1 + 2 + 3);

   System.out.println("Sum: " + Sum);

 }

}

Explanation:

You might be interested in
6.25 (Prime Numbers) A positive integer is prime if it’s divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, b
faltersainse [42]

Answer:

  1. public class Main {
  2.    public static void main (String [] args) {
  3.        for(int i = 2; i < 10000; i++){
  4.            if(isPrime1(i)){
  5.               System.out.print(i + " ");
  6.            }
  7.        }
  8.        System.out.println();
  9.        for(int i = 2; i < 10000; i++){
  10.            if(isPrime2(i)){
  11.                System.out.print(i + " ");
  12.            }
  13.        }
  14.    }
  15.    public static boolean isPrime1(int n){
  16.      
  17.        for(int i=2; i <= n/2; i++){
  18.            if(n % i  == 0){
  19.                return false;
  20.            }
  21.        }
  22.        return true;
  23.    }
  24.    public static boolean isPrime2(int n){
  25.        for(int i=2; i <= Math.sqrt(n); i++){
  26.            if(n % i  == 0){
  27.                return false;
  28.            }
  29.        }
  30.        return true;
  31.    }
  32. }

<u></u>

Explanation:

Firstly, create the first version of method to identify a prime number, isPrime1. This version set the limit of the for loop as n/2. The for loop will iterate through the number from 2 till input n / 2 and check if n is divisible by current value of i. If so, return false to show this is not a prime number (Line 22 - 26). Otherwise it return true to indicate this is a prime number.

In the main program, we call the isPrime1 method by passing the i-index value as an argument within a for-loop that will iterate through the number 2 - 10000 (exclusive).  If the method return true, print the current i value). (Line 5 - 9)

The most direct way to ensure all the prime numbers below 10000 are found, is to check the prime status from number 2 - 9999 which is amount to 9998 of numbers.

Next we create a second version of method to check prime, isPrime2 (Line 31 - 40). This version differs from the first version by only changing the for loop condition to i <= square root of n (Line 33).  In the main program, we create another for loop and  repeatedly call the second version of method (Line 13 - 17). We also get the same output as in the previous version.

8 0
3 years ago
What is the difference between a function with parameters, and a function<br> without parameters? *
Romashka [77]

Answer:

A function with out parameters cannot take any arguments or perform operations on variables passed in. A function with parameters can.

8 0
3 years ago
Student B, lives in Phoenix, Arizona and is not on vacation. Student B, submits an assignment for science class and the teacher
frozen [14]

Answer:

Don't take this for your answer though, but no unless the student copied it off of somewhere else.

The IP address might have been spoofed or they could have used a vpn.

Otherwise it would mean that someone else used their account to sign in.

Explanation:

7 0
2 years ago
What is the proper name for C4D5?<br> O cell<br> column<br> Orange<br> Orow
babunello [35]
Range. If you are referring to the Excel Format, this is a range.
3 0
3 years ago
What is the MOST important precaution to take when using social networking sites like Facebook? Use discretion Monitor friend re
leonid [27]
Uh, sure having a strong password is always nice. However, a passphrase is far superior. An example would be: My57goatsequals[4log]. Google Edward Snowden, and all your questions will be answered (concerning privacy). Oh, and by the way, use a VPN (Virtual Private Network) whenever possible.
8 0
3 years ago
Other questions:
  • When computing the cost of the basket of goods and services purchased by a typical consumer, which of the following changes from
    11·1 answer
  • In saving a Visual Basic project properly , which of the following: two components part are involved ?
    6·1 answer
  • What is collaboration
    14·1 answer
  • Need help:(!!!! I’ll mark brainliest if correct
    5·1 answer
  • What is bit in computer science? (You must select all correct answers.) Hb. A. A part of a tool, such as a router. Non. B. A bas
    6·2 answers
  • How can you change the block input so that the sprite moves in the opposite direction?
    12·1 answer
  • Which of the following commands appears in the INSERT menu or tab?
    10·1 answer
  • The range of Cell that go across the spread sheet and are identified by numbers is called​
    11·1 answer
  • Lynn wants to share parts of an essay she wrote in her slide presentation
    13·1 answer
  • Which tool can you use to display hardware utilization statistics that tell you about the operation of your computer?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!