Java | JSP | JSF Answers

Questions: 3 611

Answers by our Experts: 3 611

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

Write a program to find if a year is a leap year or not. We generally assume that if a year number is divisible by 4 it is a leap year. But it is not the only case. A year is a leap year if −

1.   It is evenly divisible by 100

2.   If it is divisible by 100, then it should also be divisible by 400

3.   Except this, all other years evenly divisible by 4 are leap years.

So the leap year algorithm is, given the year number Y,

●    Check if Y is divisible by 4 but not 100, DISPLAY "leap year"

●    Check if Y is divisible by 400, DISPLAY "leap year"

●    Otherwise, DISPLAY "not leap year"

For this program you have to take the input, that is the year number from an input file input.txt that is provided to you. The input file contains multiple input year numbers. Use a while loop to input the year numbers from the input file one at a time and check if that year is a leap year or not. Your output should go in the console.


Create a short program that will generate a random number from 0 to 100 while using Math.random and Math.round command.

 Write a program to perform the function of a Simple Interest Calculator.


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


Write a program to determine if the given grade is within the range of 1.00 to 5.00


Consider the following table:

State a java program that use Switch structure to print one of the above statements depending on the

selected day. Write comments to explain your code.

day statement

Monday " Monday is the first day of the week !"

Tuesday " Tuesday is the second day of the week !"

Wednesday "Wednesday is the third day of the week !"

Thursday "Thursday is the fourth day of the week !"

Friday “Friday is the fourth day of the week !"

Saturday “Saturday is the fifth day of the week !"

Sunday “Sunday is the sixth day of the week !"

Any other day “ Unknown day !"



• isWaterFreezing. This function should return the bool value true if the temperature stored in the temperature field is at or below the freezing point of water. Otherwise, the function should return false.

• isWaterBoiling. This function should return the bool value true if the temperature stored in the temperature field is at or above the boiling point of water. Otherwise, the function should return false.

Write a program that demonstrates the class. The program should ask the user to enter a temperature and then display a list of the substances that will freeze at that temperature and those that will boil at that temperature. For example, if the temperature is −20 the class should report that water will freeze and for 100 water will boil.



LATEST TUTORIALS
APPROVED BY CLIENTS