Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

  1.  Write a program that simulates the ATM interface.

   Use a do-while loop to display 6 services to the user

   Get the user input and display submenus appropriately.


2. Write a Boolean expression that evaluates to true if a number stored in variable num is between 1 and 100 or the number is negative


How can install eclipse java on my Windows 10 laptop?


Write a program that does the following:


1. Initialize the variables.

2. Prompt the user to enter 20 numbers.

3. For each number in the list:

a. Get the next number.

b. Output the number (echo input).

c. If the number is even: {i. Increment the even count. ii. If the number is zero, increment the zero count. }otherwise, Increment the odd count.

4. Print the results.

1. You can initialize the variables zeros, evens, and odds when you declare them.

2. Use an output statement to prompt the user to enter 20 numbers.

3. For Step 3, you can use a for loop to process and analyze the 20 numbers.

In pseudocode, this step is written as follows: for (counter = 1; counter <= 20; counter++) { a. get the number; b. output the number; c. switch (number % 2) //check the remainder { case 0: increment the even count; if (number == 0) increment the zero count; break; case 1: case -1: increment the odd count; }//end switch }//end for 4. Print the result. Output the values of the variables zeros, evens, and odds.



Write a program that does the following:


8. a. if (nthFibonacci == 1)

the desired Fibonacci number is the first Fibonacci number.

Copy the value of previous1 into current.

b. else if (nthFibonacci == 2)

the desired Fibonacci number is the second Fibonacci number.

Copy the value of previous2 into current.

c. else calculate the desired Fibonacci number as follows:

Since you already know the first two Fibonacci numbers of the

sequence, start by determining the third Fibonacci number.

i. Initialize counter to 3, to keep track of the calculated

Fibonacci numbers.

ii. Calculate the next Fibonacci number, as follows:

current = previous2 + previous1;

iii. Assign the value of previous2 to previous1.

iv. Assign the value of current to previous2.

v. Increment counter.

9. Append the nth Fibonacci number to outputString. Notice that

the nth Fibonacci number is stored in current.

10. Display the output dialog box showing the first two and the nth Fibonacci

numbers.


Create two buttons with button text "Button-1" and "Button-2" and put them in a frame using FlowLayout. Use pack () method to discard any whitespaces while putting those buttons in the frame. When you click on the "Button-1" it should display a message ("You clicked Button-1") in a popup window and when you click on the "Button-2" it should display a message ("You clicked Button-2")


What is the output of this program?

  1.     class Output {
  2.         public static void main(String args[])
  3.         {   
  4.              int x, y = 1;
  5.              x = 10;
  6.              if (x != 10 && x / 0 == 0)
  7.                  System.out.println(y);
  8.              else
  9.                  System.out.println(++y);
  10.       }
  11.     }

Select one:

a. 1

b. Runtime error owing to division by zero in if condition.

c. 2

d. Unpredictable behaviour of program.


What is the result of the following Java coding snippet?

class TestApp {

public static void main() {

int odd = 1;

if (odd) {

System.out.println("odd");

} else {

System.out.println("even");

}

}

}


Select one:

A. odd

B. Type mismatch error

C. Run-time exception

D. even


Write a program that has these overloaded search methods to do array searching:


boolean search(int[] arr, int searchKey) – searches an integer array given a search key value, returns true if searchKey is found, false if not.


Hint:

boolean found=false;

for(int i=0; i<arr.length; i++){

   if(    ){//compare the array element with the search key value

      //action taken if found

   }

}

//return something


boolean search(String[] arr, String searchKey) – searches an array of strings given a search key value, returns true if searchKey is found, false if not.

(read Comparing_Strings.doc)


In the main method, you can declare and initialize the two arrays with random values, for example:

int[] intArray={7,3,2,8,1,0,9};

String strArray={"Enchanted","Bedazzled","Divine","Delighted","Elegant"};


Use the methods in the program.



Enter a string to search in the array: bedazzled

bedazzled is found in the array



Write a program that can perform addition with these overloaded methods:


int add(int x, int y) – returns the sum of two integer values

double add(int x, double y) – returns the sum of an integer value and a double value

double add(int x, int y, double z) – returns the sum of two integer values and a double value


Use the methods in the program. (How would you use them?)



. A prime number is a number that is evenly divisible only by itself and 1. For example, the 

    number 5 is prime because it can be evenly divided only by 1 and 5. The number 6, however, 

    is not prime because it can be divided evenly by 1, 2, 4, and 6. 

    Write a method named as Prime, which takes an integer as an argument and returns true if the 

    argument is a prime number, or false otherwise. Also write main method that displays prime 

    numbers between 1 to 500


LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS