Question

What is the output of this code segment? double [] a = {-1.2, 3.1, -4.7, 38.0,...

What is the output of this code segment?

    double [] a = {-1.2, 3.1, -4.7, 38.0, 0.0};
    double temp = a[0];

    for (int i = 1; i < a.length; i++) {
        if (a[i] < temp) {
            temp = a[i];
        }
    }

    System.out.println (temp);

What does this method do? In one short English sentence describe the task accomplished by this method.

    public static int foo(int [] a)
    {
        int temp = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] < 0) {
                temp++;
            }
        }
        return temp;
    }

What does this method do? In one short English sentence describe the task accomplished by this method.

    public static char [] bar(String [] a)
    {
        char [] tmp = new char[a.length];

        for (int i = 0; i < a.length; i++) {
            if (a[i].length() > 0) {
                tmp[i] = a[i].charAt(0);
            }
            else {
                tmp[i] = ' ';
            }
        }
        return tmp;
    }

Write a static method that takes an array of integers as a parameter and returns true if the count of strictly positive values is larger than the count of strictly negative values in the array, false otherwise. A number is strictly positive if it is strictly larger than zero (i.e. it cannot equal zero). A number is strictly negative if it is strictly less than zero.

Write a static method that takes an array of integers as a parameter and returns back an integer that is the sum of all of the integers in the array.

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

What is the output of this code segment?

Ans: temp value=-4.7

What does this method do? In one short English sentence describe the task accomplished by this method.

Ans: it just counts the number of integers which are less than zero in the given array of integers

What does this method do? In one short English sentence describe the task accomplished by this method.

Ans:The code fills the array with the first character in an array of characters.if array deos not contain anything it fills with empty character.

Write a static method that takes an array of integers as a parameter and returns back an integer that is the sum of all of the integers in the array.

  public static int sum(int[] a)
    {
      int p, r;
      r = 0;
      for(p= 0; p < a.length; p++)
      {
        r = r + a[p];
      }
      return r;
    }

Write a static method that takes an array of integers as a parameter and returns true if the count of strictly positive values is larger than the count of strictly negative values in the array, false otherwise. A number is strictly positive if it is strictly larger than zero (i.e. it cannot equal zero). A number is strictly negative if it is strictly less than zero

public static boolean strictlylarger(int [] a){
int l=0;
for(int i=0;i<a.length;i++){
if(a[i]>0){
l++;
}else if(a[i]<0){
l--;
}
}
if(l>0){
return true;
}else{
return false;
}
}

Add a comment
Know the answer?
Add Answer to:
What is the output of this code segment? double [] a = {-1.2, 3.1, -4.7, 38.0,...
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
  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

  • How to write a recursive method named lessThanKFirst that receives an array of integers a and...

    How to write a recursive method named lessThanKFirst that receives an array of integers a and an integer k and rearranges the integers in a in such a way that all integers that are smaller than k come before any integers that are greater than or equal to k. As an example, suppose that a and k are: int[] a  = {35, 12, 57, 28, 49, 100, 61, 73, 92, 27, 39, 83, 52}; int k = 73; Then, the following...

  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • COMPLETE BigMerge public class BigMerge {       /*    * Returns j such that a[j][index[j]]...

    COMPLETE BigMerge public class BigMerge {       /*    * Returns j such that a[j][index[j]] is the minimum    * of the set S={a[i][index[i]] for every i such that index[i]<a[i].length}    * If the set S is empty, returns -1    * Runs in time a.length.    *    * NOTE: normally this would be private, but leave it    * public so we can test it separately from your merge.    */    public static int argMin(int [][]...

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