Question

Write code in static void main method class, which creates a boolean array called flags, size...

Write code in static void main method class, which creates a boolean array called flags, size 10, and using a for loop sets each element to alternating values (true at index zero, false at index one

Write code in a static void main method class, which creates a float array called sales, size 5, uses an initializer list to instantiate its elements with positive values having two decimal places (example 7.25), and using a for loop reads those values of each element, prints the sum of all the elements.

HW Write code in a static void main method class, which creates a character array called vowels, size 5, prompt the user to enter one at a time into a separate element the letters A E I O U then print the first letter by referencing the array list. Then print "How you doing?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code:

import java.util.Scanner;

class Main {

public static void main(String[] args) {

//creating boolean array of size 10

boolean flags[] = new boolean[10];

//for loop to set the values

for (int i=0;i<10;i++){

//checking for alternate values

if(i%2 == 0){

flags[i] = true;

}else{

flags[i] = false;

}

}

//printing flags array

for(int i=0;i<10;i++)

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

System.out.println();

//creating a float array and initializing

double numbers[] = new double[]{2.12,1.22,4.53,23.45,67.54};

//using for loop to print and sum of values

double sum = 0;

for(int i=0;i<5;i++){

System.out.println(numbers[i]+" ");

sum += numbers[i];

}

System.out.printf("Sum : %.2f",sum);

System.out.println();

//creating a character array

char vowels[] = new char[5];

Scanner sc = new Scanner(System.in);

//prompting user to enter vowels

for(int i=0;i<5;i++){

System.out.println("Etner a vowel : ");

vowels[i] = sc.next().charAt(0);

}

//printing first letter

System.out.println("First letter : "+vowels[0]);

System.out.println("How you doing?");




}

}

Add a comment
Know the answer?
Add Answer to:
Write code in static void main method class, which creates a boolean array called flags, size...
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
  • I’m giving you code for a Class called GenericArray, which is an array that takes a...

    I’m giving you code for a Class called GenericArray, which is an array that takes a generic object type. As usual this is a C# program, make a new console application, and for now you can stick all of this in one big file. And a program that will do some basic stuff with it Generic Array List What I want you to do today: Create methods for the GenericArray, Easy(ish): public void Append (T, value) { // this should...

  • Write a java program that declares 10 element array (of type integers), creates and initializes the...

    Write a java program that declares 10 element array (of type integers), creates and initializes the array, and perform the sum of elements of the array using for loop.   public class SumArray { public static void main (String[], args) { } // end of main } // end of SumArray class

  • Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method...

    Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method  Declare and initialize an array called myNums int myNums = {3, 8, 12, 4, 2, 9, 6};  Declare an int called largestNum and set it to 0.  Write a for loop that prints the array for (int index = 0; index < myNums.length; index++) { System.out.println(myNums[index] + “ “); }  Write a for loop that prints the array backwards ...

  • Part I: Create a program class named TestArrays This class should have a main() method that...

    Part I: Create a program class named TestArrays This class should have a main() method that behaves as follows: Create an integer array of size 10. Using a loop, fill the elements with increments of 5, starting with 5 in the first element. Using the array elements, sum the second, fifth and seventh elements. Display the sum with a label. Change the fourth element to 86. Subtract 9 from the ninth element. Using a loop, display the elements of the...

  • In C++ Write a program that contains a class called VideoGame. The class should contain the...

    In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....

  • Write a C code to perform the following tasks: In main: Define an array of SIZE...

    Write a C code to perform the following tasks: In main: Define an array of SIZE = 7 and initialize them with 3, 5, 7, 9, 11, 13, 15 Call function sum with the array and size as parameters Print each element of the array Print the sum In function sum. Use for-loop to calculate sum

  • 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...

  • Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating...

    Write a method public static ArrayList merge(ArrayList a, ArrayList b) that merges two array lists, alternating elements from both array lists. If one array list is shorter than the other, then alternate as long as you can and then append the remaining elements from the longer array list. For example, if a is 1 4 9 16 and b is 9 7 4 9 11 then merge returns the array list 1 9 4 7 9 4 16 9 11...

  • PrintArray vi Create a class called PrintArray. This is the class that contains the main method....

    PrintArray vi Create a class called PrintArray. This is the class that contains the main method. Your program must print each of the elements of the array of ints called aa on a separate line (see examples). The method getArray (included in the starter code) reads integers from input and returns them in an array of ints. Use the following starter code: //for this program Arrays.toString(array) is forbidden import java.util.Scanner; public class PrintArray { static Scanner in = new Scanner(System.in);...

  • JAVA Language public class ArraySkills { public static void main(String[] args) { // *********************** // For...

    JAVA Language public class ArraySkills { public static void main(String[] args) { // *********************** // For each item below you must code the solution. You may not use any of the // methods found in the Arrays class or the Collections classes // String[] myData; // 1. Instantiate the given array to hold 10 Strings. // 2. Add your name to the Array at index 0 and a friend's name to the Array at index 4 // 3. Move your...

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
ADVERTISEMENT