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
AleksandrR [38]
2 years ago
9

Subtract each element in origList with the corresponding value in offsetAmount. Print each difference followed by a space. Ex: I

f origList = {4, 5, 10, 12} and offsetAmount = {2, 4, 7, 3},
print: 2 1 3 9
import java.util.Scanner;
public class VectorElementOperations {
public static void main (String [] args) {
final int NUM_VALS = 4;
int[] origList = new int[NUM_VALS];
int[] offsetAmount = new int[NUM_VALS];
int i;
origList[0] = 20;
origList[1] = 30;
origList[2] = 40;
origList[3] = 50;
offsetAmount[0] = 2;
offsetAmount[1] = 3;
offsetAmount[2] = 6;
offsetAmount[3] = 5;
*\your code here*\
System.out.print
Computers and Technology
1 answer:
mafiozo [28]2 years ago
7 0

Answer:

Replace

*\your code here*\

System.out.print

with the following lines code

int difference;

for(int j = 0; j<=3;j++)  {

difference = origList[j] - offsetAmount[j];

System.out.print(difference+" ");

}

Also, your program is  not well ended

At the end of the above code, write the following

}

}

Explanation:

The first line of the above code segment declares an integer variable named difference

The next line declares and starts a loop using an iterative variable named j

j is declared of type integer and it takes the range of 0 to 3

The next line calculates the difference between each element of array origList and the corresponding element of offsetAmount.

This difference is saved in variable difference

The next line prints the calculated difference followed by a blank space

The last line of the code segment ends the iteration

You might be interested in
Create a class named Person that holds the following fields: two String objects for the person’s first and last name and a Local
faust18 [17]

Answer:

Check the explanation

Explanation:

I have added comments in the code for your easy reference.

//Code for this solution

//File: Person.java

import java.time.LocalDate;

//Person class

public class Person {

//Member variables

private String firstName;

private String lastName;

private LocalDate birthDate;

//Paramterized constructors that initializes all the member variables

public Person(String fName, String lName, LocalDate bDate) {

firstName = fName;

lastName = lName;

birthDate = bDate;

}

//Getter methods for each of the member variables

public String getFirstName() {

return firstName;

}

public String getLastName() {

return lastName;

}

public LocalDate getBirthDate() {

return birthDate;

}

}

//File: Couple.java

//Couple class

public class Couple {

//Member variables

private Person person1;

private Person person2;

//Paramterized constructors that initializes all the member variables

public Couple(Person p1, Person p2) {

person1 = p1;

person2 = p2;

}

//Getter methods for each of the member variables

public Person getFirstPerson() {

return person1;

}

public Person getSecondPerson() {

return person2;

}

}

 

//File: Wedding.java

import java.util.Date;

//Wedding class

public class Wedding {

//Member variables

private Date weddingDate;

private Couple couple;

private String location;

//Paramterized constructors that initializes all the member variables

public Wedding(Date date, Couple c, String wedLocation) {

weddingDate = date;

couple = c;

location = wedLocation;

}

//Getter methods for each of the member variables

public Date getWeddingDate() {

return weddingDate;

}

public Couple getCouple() {

return couple;

}

public String getLocation() {

return location;

}

}

//File: TestWedding.java

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.time.LocalDate;

import java.time.format.DateTimeFormatter;

//Test driver class

public class TestWedding {

private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");

//Method to display Wedding details - Couple, Location and Wedding date

public static void displayWedding(Wedding w) {

System.out.println("");

System.out.println("=== Wedding details ===");

Person p1 = w.getCouple().getFirstPerson();

Person p2 = w.getCouple().getSecondPerson();

System.out.println(p1.getFirstName() + " " + p2.getLastName() + "(born " + p1.getBirthDate().format(DateTimeFormatter.ISO_DATE) + ")"

+ " weds " + p2.getFirstName() + " " + p2.getLastName() + "(born " + p2.getBirthDate().format(DateTimeFormatter.ISO_DATE) + ")");

System.out.println("ON");

System.out.println( simpleDateFormat.format( w.getWeddingDate()));

System.out.println("AT");

System.out.println(w.getLocation());

}

//Test method - to create Person, Couple and Wedding objects

public static void main(String[] args) throws ParseException {

//Create Person objects

Person p10 = new Person("John", "Howard", LocalDate.of(2000, 10, 1));

Person p11 = new Person("Mary", "Eliza", LocalDate.of(2002, 1, 2));

//Create Couple object with above data

Couple c1 = new Couple(p10, p11);

//Create Wedding Object

Wedding w1 = new Wedding( simpleDateFormat.parse("2019-05-06"), c1, "CountrySide");

//Display Wedding details

displayWedding(w1);

Person p20 = new Person("James", "Howler", LocalDate.of(1999, 5, 1));

Person p21 = new Person("Jenny", "Hertz", LocalDate.of(2005, 4, 25));

Couple c2 = new Couple(p20, p21);

Wedding w2 = new Wedding(simpleDateFormat.parse("2019-10-02"), c2, "Mary Islands");

displayWedding(w2);

}

}

Kindly check the attached image below for the code output.

7 0
2 years ago
Read 2 more answers
Which mitigation technique would prevent rogue servers from providing false ip configuration parameters to clients?
IrinaVladis [17]
DHCP snooping is a mitigation technique<span> to </span>prevent rogue<span> DHCP </span>servers  <span>from </span>providing false IP configuration parameters to clients.  DHCP snooping<span> is a security feature that acts like a firewall between untrusted hosts and trusted </span>DHCP<span> servers. It is</span><span> a series of techniques applied to improve the security of a </span>DHCP<span> infrastructure. </span>
6 0
2 years ago
Read 2 more answers
Email communication has its own set of etiquette guidelines for users to follow if they want to be effective communicators. Whic
Lilit [14]
D. Indicate the topic of the email in the subject line.
5 0
2 years ago
Read 2 more answers
Value is always _____________ aligned in a cell. ​
Nadya [2.5K]

Answer:

Right

Explanation:

7 0
1 year ago
You are a security consultant and have been hired to evaluate an organization's physical security practices. All employees must
7nadin3 [17]

Answer:

D. Replace the smart card reader with a key code lock.

Explanation:

In other to increase the security of the company, the best security practice would be to replace the smart card reader with a key code lock. This is because, with the smart card reader, an unauthorised person who was able to pick up one of the cards could be able to access the secured work station.

<em>On the other hand, if the area is accessed with key code lock, the, it is only the person who knows the code that will be able to access the secured work area. Of course, the key code will vary from one individual to another in the organization.</em>

4 0
2 years ago
Other questions:
  • A workgroup database is a(n) _____ database
    9·1 answer
  • Match the following technologies with their applications.
    9·1 answer
  • In Python, what kind of error is returned by the following code? (e.g. NameError, ValueError, IOError, etc.) def my_func(n1, n2)
    8·1 answer
  • Write the definition of a function named quadratic that receives three double parameters a, b, c. If the value of a is 0 then th
    12·1 answer
  • When you park on a hill, think about which way _____.
    6·2 answers
  • Write a algorithm to attend birthday party​
    8·2 answers
  • B. Write a function that takes one double parameter, and returns a char. The parameter represents a grade, and the char represen
    7·1 answer
  • Implement the function couple, which takes in two lists and returns a list that contains lists with i-th elements of two sequenc
    8·1 answer
  • PLEASE AWNSER 50 POINTS PLUS BRAINLEST ILL FAIL MY GRADE IF I DONT AWNSER IN A HOUR!
    15·1 answer
  • Most ________ are accompanied by several common utility programs, including a search program, a storage management program, and
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!