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

Java Lab Report Rabin Bashyal

The document contains multiple Java programs that demonstrate various programming concepts, including finding the largest number among three inputs, checking command-line arguments, converting minutes into years and days, performing arithmetic operations on two integers, and illustrating different loop structures. Each program includes a description, code, output example, and a conclusion summarizing its success. The overall focus is on basic Java programming techniques and user interaction.

Uploaded by

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

Java Lab Report Rabin Bashyal

The document contains multiple Java programs that demonstrate various programming concepts, including finding the largest number among three inputs, checking command-line arguments, converting minutes into years and days, performing arithmetic operations on two integers, and illustrating different loop structures. Each program includes a description, code, output example, and a conclusion summarizing its success. The overall focus is on basic Java programming techniques and user interaction.

Uploaded by

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

1.

Largest Number Among Three Numbers

Description
This program takes three numbers from user and finds the largest using conditional
statements.

Program
import [Link];

public class LargestNumber {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Rabin Bashyal BCA 3rd sem");

[Link]("Enter first number: ");


int a = [Link]();

[Link]("Enter second number: ");


int b = [Link]();

[Link]("Enter third number: ");


int c = [Link]();

int largest = a;
if(b > largest) largest = b;
if(c > largest) largest = c;

[Link]("Largest number is: " + largest);


}
}

Output (Java Console Style)


Rabin Bashyal BCA 3rd sem
Enter first number: 45
Enter second number: 78
Enter third number: 23
Largest number is: 78

Short Description of Code


Uses conditional statements to compare three numbers and determine largest.
Conclusion
Successfully finds the largest of three numbers.
2. Command-Line Arguments Check

Description
Checks whether command-line arguments are provided.

Program
public class CommandLineCheck {
public static void main(String[] args) {
[Link]("Rabin Bashyal BCA 3rd sem");

if([Link] == 0){
[Link]("No arguments provided");
} else {
for(String s : args){
[Link](s);
}
}
}
}

Output (Java Console Style)


Rabin Bashyal BCA 3rd sem
Java
BCA
ThirdSem

Short Description of Code


Uses args[] array to check and display command-line arguments.

Conclusion
Successfully checks and displays command-line arguments.
3. Convert Minutes into Years and Days

Description
Converts minutes into years and days using arithmetic operations.

Program
import [Link];

public class MinutesConversion {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Rabin Bashyal BCA 3rd sem");

long minutes = [Link]();

long years = minutes / (60 * 24 * 365);


long days = (minutes / (60 * 24)) % 365;

[Link]("Years: " + years);


[Link]("Days: " + days);
}
}

Output (Java Console Style)


Rabin Bashyal BCA 3rd sem
Enter minutes: 1000000
Years: 1
Days: 329

Short Description of Code


Uses arithmetic conversion formulas with division and modulus.

Conclusion
Successfully converts minutes into years and days.
4. Operations on Two Integers

Description
Performs arithmetic, comparison and math operations on two integers.

Program
import [Link];

public class IntegerOperations {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);

[Link]("Rabin Bashyal BCA 3rd sem");

int a = [Link]();
int b = [Link]();

[Link]("Sum = " + (a+b));


[Link]("Difference = " + (a-b));
[Link]("Product = " + (a*b));
[Link]("Average = " + ((a+b)/2.0));
[Link]("Distance = " + [Link](a-b));
[Link]("Max = " + [Link](a,b));
[Link]("Min = " + [Link](a,b));
}
}

Output (Java Console Style)


Rabin Bashyal BCA 3rd sem
Enter first integer: 20
Enter second integer: 10
Sum = 30
Difference = 10
Product = 200
Average = 15.0
Distance = 10
Max = 20
Min = 10

Short Description of Code


Uses arithmetic operators and Math class functions.
Conclusion
Successfully performs all required operations.
5. Pizza Distribution Using Loops

Description
Demonstrates for, while, do-while and foreach loops.

Program
public class PizzaDistribution {
public static void main(String[] args) {

int pizzaSlices = 8;
String[] friends = {"Ram","Shyam","Hari","Sita"};

[Link]("Rabin Bashyal BCA 3rd sem");

for(String f : friends){
[Link](f + " got 1 slice");
}

[Link]("Extra hungry friend gets slices...");


}
}

Output (Java Console Style)


Rabin Bashyal BCA 3rd sem
Ram got 1 slice
Shyam got 1 slice
Hari got 1 slice
Sita got 1 slice
Extra hungry friend gets slices...

Short Description of Code


Demonstrates different loop structures in Java.

Conclusion
Successfully demonstrates loop concepts.

You might also like