Jump to content

Recommended Posts

Posted

 

3.Write a program called Convert for inserting a

distance in kilometers from the keyboard and convert it into miles (a mile is 1609 km).

 

 

  Reveal hidden contents

 

 

 

4.Write Java program to allow the user to input his/her age. Then the program will show if the person is eligible to vote. A person who is eligible to vote must be older than or equal to 18 years old.

Enter your age: 18

You are eligible to vote.

 

 

  Reveal hidden contents

 

 

 

5.Write a Java program to determine whether an input number is an even number.

 

 

  Reveal hidden contents

 

 

 

6.Write a Java program that determines a student’s grade.

The program will read three types of scores(quiz, mid-term, and final scores) and determine the grade based on the following rules:

-if the average score >=90% =>grade=A

-if the average score >= 70% and <90% => grade=B

-if the average score>=50% and <70% =>grade=C

-if the average score<50% =>grade=F

See the example output below:

Quiz score: 80

Mid-term score: 68

Final score: 90

Your grade is B.

 

  Reveal hidden contents

 

 

 

7.Write a Java program to calculate the revenue from a sale based on the unit price and quantity of a product input by the user.

 

The discount rate is 10% for the quantity purchased between 100 and 120 units, and 15% for the quantity purchased greater than 120 units. If the quantity purchased is less than 100 units, the discount rate is 0%. See the example output as shown below:

Enter unit price: 25

 

Enter quantity: 110

 

The revenue from sale: 275.0$

 

After discount: 2475.0$(10.0%)

 

 

  Reveal hidden contents

 

 

 

8.Write a Java program to detect key presses.(use switch)

 

If the user pressed number keys( from 0 to 9), the program will tell the number that is pressed, otherwise, program will show "Not allowed".

 

 

  Reveal hidden contents

 

 

 

9. Write a Java program that allows the user to choose the correct answer of a question.(use switch)

 

See the example below:

What is the correct way to declare a variable to store an integer value in Java?

a. int 1x=10;

b. int x=10;

c. float x=10.0f;

d. string x="10";

Enter your choice: c

 

 

  Reveal hidden contents

 

 

 

10.By using do while loop, write Java program to prompt the user to choose the correct answer from a list of answer choices of a question.

 

The user can choose to continue answering the question or stop answering it. See the example below:

What is the command keyword to exit a loop in Java?

 

a. int

 

b. continue

 

c. break

 

d. exit

 

Enter your choice: b

 

Incorrect!

 

Again? press y to continue:

 

 

  Reveal hidden contents

 

 

 

11.By using while loop Write Java program to prompt the user to choose the correct answer from a list of answer choices of a question.

 

The user can choose to continue answering the question or stop answering it. See the example below:

What is the command keyword to exit a loop in Java?

 

a. int

 

b. continue

 

c. break

 

d. exit

 

Enter your choice: b

 

Incorrect!

 

Again? press y to continue:

 

 

  Reveal hidden contents

 

 

 

12.Using a while loop Write a program that asks the user to enter a character then the program displays the character. So on! The program stops only if the user enters the character 't'.

 

 

  Reveal hidden contents

 

 

 

13.Using do while loop Write a program that asks the user to enter a character then the program displays the character. So on! The program stops only if the user enters the character 't'.

 

 

  Reveal hidden contents

 

Posted (edited)

Nice share for noobies in java.

Although, you have to add the source.

 

The topic moved to the right section!

Edited by MeVsYou

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock