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

Using any loop of your choice create a program that will prompts the user for two numbers and do calculations as follows, starting from the smallest number add the next number if its even or subtract it if its odd, repeat this until you get to the last number. i.e. if you start at 2 to 4, then 2 – 3 + 4( - because 3 is odd and + because 4 is even)

Sample Run1

Enter two numbers: 1 4

Output1: calculations = 1 + 2 – 3 + 4 = 4

Sample Run2

Enter two numbers: 5 10

Output2: 5 + 6 – 7 + 8 – 9 + 10 = 10

Using a while loop create a program that will prompts the user for two numbers and then print out a list using the two given numbers, starting from the small number to the big number

Sample Run1

Enter two numbers: 1 10

Output1: 1 2 3 4 5 6 7 8 9 10

Sample Run2

Enter two numbers: 9 5

Output2: 5 6 7 8 9


Using a do-while loop create a program that will prompt the user for a number and then print out a list 5 odd numbers above the given number(inclusive).



Find the error and correct it:

• if(x>=3)

System.out.println(“ number is equal to 3 “) ;

System.out.println(“ or number is greater than 3 “) ;

else

System.out.println(“ number is not greater or equal to 3 “) ;


Correct the error in the following code : there is more than 1 error :


1-

importjava.util.Scanner; // import Scanner class publicclass We {

publicstaticvoid main(String[] args) {

Scanner input = newScanner(System.in);// create Scanner object System.out.println("number:");

intg= input.nextInt(); // Declare and read

switch(g==);

case1 :System.out.println("case1"); break;

case2 :System.out.println("case2"); break;

    


default :System.out.println("default"); }

}


2-

charg= 'a'; switch(g)

{

Case r :System.out.println("case1");

break;

case u: System.out.println("case2"); break;

default :System.out.println("default"); }


6-Write a program to calculate the area of a circle. Use the formula Pi * r * r to work the program. Remember Pi is a constant and r is a variable entered by the user at runtime (once the program is running). Format the answer to 2 decimal places.


Rewrite the following program using Switch:

if (x == 1) {

system.out.println("x is 1");

}

else if (x == 2) {

system.out.println("x is 2");

}

else {

system.out.println( "value of x unknown"); }



Using a switch statement, write a program that prompts the user for a numeric code and two operands. The numeric codes of 1, 2, 3, and 4 represents addition, subtraction, multiplication, and division respectively. Before division, your program should check whether the second operand is not zero. If it is, it should display “Division by zero not allowed” to the screen.

                     


Write a java program for the following-

Class person

Derive two classes-student and employee [identify inheritance]

For student

Input: Name, roll no, marks in 4 subjects (use arrays of object]

Output: student information, total marks [create necessary function, Use of constructor

For Employee

Input: empno, empname, basic

Process:

a. DA=50%of basic

N

b. HRA=25%of basic

c. CCA=Rs240/-

d. PF=10%of basic


You have been requested to create a program that that helps the Namibian Defence Forces’ (NDF) Captain to calculates the BMI of a person (BMI = weight/height2) and also determine whether the person has also completed running 10 km in the required time. Men should complete 10km in less than 60 minutes for them to be accepted. Women should do that under 80 minutes. Both males and females are accepted if their BMI is less than 25 and greater than 18.5. For 2018 intake, there are already 6 males selected and 1 female.

Sample Run 1

Welcome to NDF Captain's Selection Aid.

***************************************

Gender: male

Mass in kilograms: 82

Height in metres: 1.82

Time for completing 10 km in minutes: 45

Output1: Candidate Selected! The number of males is now 7.





LATEST TUTORIALS
APPROVED BY CLIENTS