Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
13 views

Java Lab Manual with solution 1

The document contains three Java programming examples. The first example prints 'Hello, World!', the second compares two numbers using relational and logical operators, and the third finds the largest of three numbers using if-else statements. Each example demonstrates basic programming concepts in Java.

Uploaded by

Mukesh Surela
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Java Lab Manual with solution 1

The document contains three Java programming examples. The first example prints 'Hello, World!', the second compares two numbers using relational and logical operators, and the third finds the largest of three numbers using if-else statements. Each example demonstrates basic programming concepts in Java.

Uploaded by

Mukesh Surela
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Q1. Write a program that prints “Hello, World!”?

public class HelloWorld


{
public static void main(String[] args)
{
System.out.println("Hello, World!");
}
}

Q2. Write a program to compare two numbers using relational operators.

public class OperatorsExample {


public static void main(String[] args) {
int num1 = 10, num2 = 5;
System.out.println("Sum: " + (num1 + num2));
System.out.println("Difference: " + (num1 - num2));

// Relational operators
System.out.println("num1 is greater than num2: " + (num1 >
num2));

// Logical operators
boolean condition = (num1 > 0 && num2 < 10);
System.out.println("Both conditions are true: " + condition);
}
}

Q3. Write a program to find the largest of three numbers using if-else?
// If-else example
public class ControlFlowExample {
public static void main(String[] args) {
int a = 10, b = 20, c = 5;

if (a > b && a > c) {


System.out.println("a is the largest");
} else if (b > c) {
System.out.println("b is the largest");
} else {
System.out.println("c is the largest");
}
}
}

You might also like