[Go to site: main page, start]

0% found this document useful (0 votes)
7 views7 pages

Java Programs for Blood Donation and Menu

Uploaded by

yaxeval553
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

Java Programs for Blood Donation and Menu

Uploaded by

yaxeval553
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Output (marks = 75):

import [Link];

public class BloodDonation {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

// Input age

[Link]("Enter your age: ");

int age = [Link]();

// Input weight

[Link]("Enter your weight (in kg): ");

int weight = [Link]();

// Nested if condition

if (age >= 18) { // outer if

if (weight >= 50) { // inner if

[Link](" You are eligible to donate blood.");

} else {

[Link](" You are not eligible. Weight must be at least 50 kg.");

} else {

[Link](" You are not eligible. Age must be 18 or above.");

[Link]();

}
Sum of first 10 numbers

Sum of first 10 numbers = 55


public class SwitchExample {

public static void main(String[] args) {

int day = 3;

switch(day) {

case 1:

[Link]("Monday");

break;

case 2:

[Link]("Tuesday");

break;

case 3:

[Link]("Wednesday");

break;

case 4:

[Link]("Thursday");

break;

case 5:

[Link]("Friday");

break;

case 6:

[Link]("Saturday");

break;

case 7:

[Link]("Sunday");

break;

default:
[Link]("Invalid Day");

Hotel Menu System

import [Link];

public class HotelMenu {

public static void main(String[] args) {

Scanner sc = new Scanner([Link]);

[Link]("----- Hotel Menu -----");

[Link]("1. Pizza");

[Link]("2. Burger");

[Link]("3. Sandwich");

[Link]("4. Pasta");

[Link]("5. Coffee");

[Link]("Enter your choice (1-5): ");

int choice = [Link]();

switch(choice) {

case 1:

[Link]("You ordered Pizza ");

break;

case 2:

[Link]("You ordered Burger ");


break;

case 3:

[Link]("You ordered Sandwich ");

break;

case 4:

[Link]("You ordered Pasta ");

break;

case 5:

[Link]("You ordered Coffee ");

break;

default:

[Link]("Invalid Choice ");

[Link]();

Output :
public class InvertedTriangle {

public static void main(String[] args) {

int rows = 5;

for (int i = 0; i < rows; i++) { // outer loop → rows

// print spaces

for (int j = 0; j < i; j++) {

[Link](" ");

// print stars

for (int k = 0; k < rows - i; k++) {

[Link]("*");

[Link](); // next line

} Output :

*****

****

***

**

You might also like