Write a method named square that accepts an integer argument and returns the square of that argument

Assume that x is a variable that has been declared as a double and been given a value .

Write an expression to compute the quartic root of x. The quartic root of a number is the square root of its square root.

EXAMPLES: For example, the quartic root of 16.0 is 2.0 because: the square root of 16.0 is 4.0 and the square root of 4.0 is 2.0. Another example: the quartic root of 81.0 is 3.0 because the square root of 81.0 is 9.0 and the square root of 9.0 is 3.0. Thus, to find the quartic root of a number you take the square root of the number and then take the square root of that.

In this exercise you must find the quartic root of x in a single expression -- you must not write any statements . Also, you may only use the sqrt() static method defined in the Math class -- no other methods .

(HINT: you will need to call the Math.sqrt() method twice-- and you will need to pass the return value of one of those calls as argument to the other call. AND REMEMBER: write an expression , not a statement .)

  • Flashcards

  • Learn

  • Test

  • Match

  • Flashcards

  • Learn

  • Test

  • Match

Terms in this set (14)

Find the error in the following method definition:

// This method has an error!
public static void sayHello();
{
System.out.println("Hello");
}

The header should NOT be terminated with a semicolon.

Look at the following method header:

public static void showValue(int x)

The following code has a call to the showValue method. Find the error.

int x = 8; showValue(int x); // Error!

The int data type should not be listed in the method call.

The statement should read: showValue(x);

Find the error in the following method definition:

// This method has an error!
public static double timesTwo(double num)
{
double result = num * 2;
}

The method should have a return statement that returns a double value.

Find the error in the following method definition:

// This method has an error!
public static int half(double num)
{
double result = num / 2.0; return result;
}

The method's return type should be double instead of int.

Examine the following method header, and then write an example call to the method:

public static void doSomething(int x)

doSomething(25);

Here is the code for the displayValue method, shown earlier in this chapter:

For each of the following code segments, indicate whether it will successfully compile or cause an error:

a.) displayValue(100);
b. ) displayValue(6.0);
c.) short s = 5;
d.) displayValue(s);
e.) long num = 1;
f. ) displayValue(num);
h.) displayValue(6.2f);
i.) displayValue((int) 7.5);

a.) This statement will compile successfully.
b.) This statement will cause an error because 6.5 cannot be automatically converted to an int.
c.) This statement will compile successfully.
d.) This statement will cause an error because a long cannot be automatically converted to an int.
e.) This statement will cause an error because the float value 6.2 cannot be automatically converted to an int.
f.) This statement will compile successfully.

Look at the following method header:

public static void myMethod(int a, int b, int c)

Now look at the following call to myMethod:

myMethod(3, 2, 1);

When this call executes, what value will be stored in a? What value will be stored in b? What value will be stored in c?

The value 3 will be stored in a, 2 will be stored in b, and 1 will be stored in c.

What will the following program display?

public class ChangeParam
{
public static void main(String[] args)
{
int x = 1; double y = 3.4;
System.out.println(x + " " + y); changeUs(x, y);
System.out.println(x + " " + y);
}
public static void changeUs(int a, double b)
{
a = 0;
b = 0.0;
System.out.println(a + " " + b);
}
}

1 3.4
0 0.0
1 3.4

A program contains the following method definition:

public static int cube(int num)
{
return num num num;
}

Write a statement that passes the value 4 to this method and assigns its return value to a variable named result.

result = cube(4);

A program contains the following method:

public static void display(int arg1, double arg2, char arg3)
{
System.out.println("The values are " + arg1 + ", " + arg2 + ", and " + arg3); }

Write a statement that calls this method and passes the following variables as arguments:

char initial = 'T';
int age = 25;
double income = 50000.00;

display(age, income, initial);

Write a method named timesTen. The method should accept a double argument, and return a double value that is ten times the value of the argument.

public static double timesTen(double num)
{
return num * 10.0;
}

Write a method named square that accepts an integer argument and returns the square of that argument.

public static int square(int num)
{
return num * num;
}

Write a method named getName that prompts the user to enter his or her first name, and then returns the user's input.

// Assume java,util.Scanner has been imported.
public static String getName()
{
String name; Scanner keyboard = new Scanner(System.in);
System.out.print("Enter your first name: ");
name = keyboard.nextLine();
return name;
}

Write a method named quartersToDollars. The method should accept an int argument that is a number of quarters, and return the equivalent number of dollars as a double. For example, if you pass 4 as an argument, the method should return 1.0; and if you pass 7 as an argument, the method should return 1.75.

public static double quartersToDollars(int quarters)
{
double dollars = quarters * 0.25; return dollars;
}

Sets with similar terms

chapter 5 part1

50 terms

muk

chapter 5 part1

50 terms

ESchmidt15

CS2336 Ch. 6 Checkpoints

19 terms

gsn313

Java Chapter 5

26 terms

burgas

Sets found in the same folder

CSCE 111 Ch. 8 Review

18 terms

bpatterson54242

JAVA Ch. 6 Questions

19 terms

just4lizzy

Java Chapter 5 Methods

65 terms

NightCloudSurfer

Ch. 10

33 terms

Jason_Fults4

Other sets by this creator

Geology/Earth Science Chapter 20

9 terms

chelsi_sherrell4

Relational Final (Chapters 7 + 10), Chapters 11 +…

354 terms

chelsi_sherrell4

Relational Final (Chapters 13 + 14)

109 terms

chelsi_sherrell4

Relational Final (Chapters 11 + 12)

133 terms

chelsi_sherrell4

Verified questions

COMPUTER SCIENCE

True/False: A list must contain at least one item.

Verified answer

COMPUTER SCIENCE

This string method returns a copy of a string with all the alphabetic letters converted to uppercase. a. uppercase() b. case_upper() c. upper() d. to_upperCase()

Verified answer

COMPUTER SCIENCE

An English Christmas carol, “The Twelve Days of Christmas,” dates from the late 1700s. The twelve verses in the song are cumulative, each verse adding an additional gift given by “my true love.” The twelfth verse says “On the twelfth day of Christmas, my true love gave to me . . .” 12 Drummers Drumming. 11 Pipers Piping. 10 Lords-a-Leaping . . . and so forth down to . . . 3 French Hens. 2 Turtle Doves.

Verified answer

COMPUTER SCIENCE

Consider a file system that uses inodes to represent files. Disk blocks are 8KB in size, and a pointer to a disk block requires 4 bytes. This file system has 12 direct disk blocks, as well as single, double, and triple indirect disk blocks. What is the maximum size of a file that can be stored in this file system?

Verified answer

Recommended textbook solutions

Write a method named square that accepts an integer argument and returns the square of that argument

Information Technology Project Management: Providing Measurable Organizational Value

5th EditionJack T. Marchewka

346 solutions

Write a method named square that accepts an integer argument and returns the square of that argument

Introduction to Algorithms

3rd EditionCharles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

720 solutions

Write a method named square that accepts an integer argument and returns the square of that argument

Fundamentals of Database Systems

7th EditionRamez Elmasri, Shamkant B. Navathe

687 solutions

Write a method named square that accepts an integer argument and returns the square of that argument

Service Management: Operations, Strategy, and Information Technology

7th EditionJames Fitzsimmons, Mona Fitzsimmons

103 solutions

Other Quizlet sets

Week One

39 terms

Newmanto

week 4 test

61 terms

taylneve

Related questions

QUESTION

Since the Python list methods are written in compiled C code, using the Python list to write a program will always be faster than a linked list implemented in Python.

3 answers

QUESTION

SR 20.12 What imbalance is fixed by a leftright rotation?

2 answers

QUESTION

True or False: The weight of the MST depends on the starting vertex.

2 answers

QUESTION

T/F: bully algorithm is not an example of Ordered Hashing

15 answers

How do you square a number in Java?

Squaring a number in Java can be accomplished in two ways. One is by multiplying the number by itself. The other is by using the Math. pow() function, which takes two parameters: the number being modified and the power by which you're raising it.

How do you code a square root in Java?

Java sqrt() method with Examples Math. sqrt() returns the square root of a value of type double passed to it as argument. If the argument is NaN or negative, then the result is NaN. If the argument is positive infinity, then the result is positive infinity.

How do you find a perfect square in Java?

Output 2:.
Suppose, n is a number that we want to check..
Create a for loop that executes from 1 to n/2..
Calculate x=i*i, for each iteration..
The variable x has the following three conditions: If x=n, the given number is perfect square. If x>n, n is not a perfect square. Continue if the above two conditions are not true..