Question

a) Explain how can an array store variables of different types. (b) Include a code example....

a) Explain how can an array store variables of different types. (b) Include a code example.

Please don't copy and paste another answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Normal array store variables of same type variables.
  • Using Objects we can create the arrays.
  • This object arrays can hold different type variables.
  • Simply object arrays are hetrogeneous collection of data variables.

Syntax:

Object[] arrayName = new Object[20];

Example:

import java.util.Scanner;

class Main {

public static void main(String[] args) {

Object[] array = new Object[20];

String str1 = new String("Hii Your score is "); // String data type

array[0] = str1; // Asign string to the array

double marks=92.86;

array[1] = marks; // Asign double type to the array

String str2 = new String(" Out of "); // String data type

array[2] = str2; // Asign string to the array

int maxMarks=100;

array[3] = maxMarks; // Asign int type to the array

for(int i=0;i<4;i++) // Loop rund for 4 times

{

System.out.print(array[i]); // print array which contain variables of different types

}

System.out.println();

}

}

Output:

Add a comment
Know the answer?
Add Answer to:
a) Explain how can an array store variables of different types. (b) Include a code example....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please copy and paste the plot. Please copy and paste the code so I can test...

    Please copy and paste the plot. Please copy and paste the code so I can test it :) Please do not comment something like "Don't have Matlab". If you don't have the software, you don't need to answer anything.

  • Q6 Explain how different types of individual will conform to different types of analysis and design...

    Q6 Explain how different types of individual will conform to different types of analysis and design stereotypes. [2 Marks] Please do not write the answer - use word format

  • Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in...

    Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...

  • What makes ANCOVA different from ANOVA? a. ANCOVA can include dummy variables. b. ANCOVA can include...

    What makes ANCOVA different from ANOVA? a. ANCOVA can include dummy variables. b. ANCOVA can include one or more continuous variables that predict the outcome. c. ANCOVA can include continuous variables that are not part of the main experimental manipulation but influence the dependent variable. d. ANCOVA can include continuous variables that are not part of the main experimental manipulation but influence the independent variable.

  • Explain the different types of financial intuitions? Please provide an example of each

    Explain the different types of financial intuitions? Please provide an example of each

  • Q2. Discuss how electronic order entry system (CPOE) can improve healthcare at different levels? Please, Please,...

    Q2. Discuss how electronic order entry system (CPOE) can improve healthcare at different levels? Please, Please, Please and Please… 1. I need new and unique answers, please. (Use your own words, don't copy and paste, even when you answer like theses answers before.) 2. Please Use your keyboard to answer my Questions. (Don't use handwriting) 3. Please and please i need a good and a perfect answers. 4. I prefer if you can to help me to put your References...

  • Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use...

    Please, i need Unique answer, Use your own words (don't copy and paste). *Please, don't use handwriting. Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need Unique answer, Use your own words (don't copy and paste).Please, i need...

  • can someone please comment through this code to explain me specifically how the variables and arrays...

    can someone please comment through this code to explain me specifically how the variables and arrays are working? I am just learning arrays code is below assignment C++ Programming from Problem Analysis to Program Design by D. S. Malik, 8th ed. Programming Exercise 12 on page 607 Lab9_data.txt Jason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into a notebook. At the...

  • C++ programming. Please provide copy/paste code and a screenshot of the code being ran in the...

    C++ programming. Please provide copy/paste code and a screenshot of the code being ran in the compiler. Vertebrates are the types of animals that typically have backbones with a bony skeleton and a brain. Vertebrates can be mammals, reptiles, amphibians, fish, and birds. Based on this information, do the following: Create a C++ hierarchy of the vertebrates class along with the attributes (variables) and behaviors (functions) using C++ syntax. Is this an example of single inheritance or multiple inheritance? Why...

  • In C++ language, implement a class that can sort an array of numbers using all three...

    In C++ language, implement a class that can sort an array of numbers using all three algorithms we have seen in this course, but each method updates a “counter” value every time it accesses the array. Have it print this at the end of the sorting process. Store the array values in an “original” array so you don’t have to re-type it for different sorts (since each sort alters the array), and have the sort modify a copy. Note: IF...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT