Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9f61866

Browse files
Code
1 parent a15f220 commit 9f61866

30 files changed

+980
-0
lines changed
22.8 KB
Binary file not shown.

‎Calc/Add.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package Calc;
2+
3+
import java.util.Scanner;
4+
5+
public class Add {
6+
int sum;
7+
public void sum()
8+
{
9+
System.out.print("Enter the first number: ");
10+
Scanner sc = new Scanner(System.in);
11+
int firstNum = sc.nextInt();
12+
System.out.print("Enter the second number: ");
13+
int secondNum = sc.nextInt();
14+
sum = firstNum+secondNum;
15+
System.out.println("Sum=" + sum);
16+
}
17+
}

‎Calc/Subtract.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package Calc;
2+
3+
import java.util.Scanner;
4+
5+
public class Subtract {
6+
int difference;
7+
public void subtract()
8+
{
9+
System.out.print("Enter the first number: ");
10+
Scanner sc = new Scanner(System.in);
11+
int firstNum = sc.nextInt();
12+
System.out.print("Enter the second number: ");
13+
int secondNum = sc.nextInt();
14+
difference = firstNum-secondNum;
15+
System.out.println("Difference=" + difference);
16+
}
17+
}

‎Q10_Overload_Area_fun.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//Q10. WAP to show the overloading of area function.
2+
package JAVA_Lab_File;
3+
4+
import java.util.Scanner;
5+
6+
public class Q10_Overload_Area_fun {
7+
static void area(double radius){
8+
double area = Math.PI * radius * radius;
9+
System.out.print("Area of Circle is: " + String.format("%.5f", area) + " sq. units");
10+
}
11+
static void area(double base, double height){
12+
double area = 0.5*base*height;
13+
System.out.print("Area of Triangle is: " + String.format("%.5f", area) + " sq. units");
14+
}
15+
public static void main(String[] args) {
16+
Scanner sc = new Scanner(System.in);
17+
System.out.println("Calculate Area: \n1.Circle\n2.Triangle\nChoice: ");
18+
int choice = sc.nextInt();
19+
if(choice == 1){
20+
System.out.print("Enter the radius of the circle: ");
21+
double radius = sc.nextDouble();
22+
area(radius);
23+
} else if (choice == 2) {
24+
System.out.print("Enter the base and height of the triangle: ");
25+
double base = sc.nextDouble();
26+
double height = sc.nextDouble();
27+
area(base, height);
28+
}else {
29+
System.out.println("Invalid choice");
30+
}
31+
}
32+
}

‎Q11_isArmstrong.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//Q11. WAP to check whether a given number is Armstrong or not.
2+
package JAVA_Lab_File;
3+
4+
public class Q11_isArmstrong {
5+
public static void main(String[] args) {
6+
7+
int number = 153, originalNumber, remainder, result = 0;
8+
originalNumber = number;
9+
10+
while (originalNumber != 0)
11+
{
12+
remainder = originalNumber % 10;
13+
result += Math.pow(remainder, 3);
14+
originalNumber /= 10;
15+
}
16+
if(result == number) {
17+
System.out.println(number + " is an Armstrong number.");
18+
} else {
19+
System.out.println(number + " is not an Armstrong number.");
20+
}
21+
}
22+
}

‎Q12_Implement_interface.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//Q12. WAP to check whether a given number is Armstrong or not.
2+
package JAVA_Lab_File;
3+
4+
interface Animal {
5+
public void animalSound();
6+
public void sleep();
7+
}
8+
class Siyaar implements Animal {
9+
public void animalSound() {
10+
System.out.println("The Siyaar howls: Aaooo Aaooo");
11+
}
12+
public void sleep() {
13+
System.out.println("Zzz");
14+
}
15+
}
16+
public class Q12_Implement_interface {
17+
18+
public static void main(String[] args) {
19+
Siyaar S_Siyaar = new Siyaar();
20+
S_Siyaar.animalSound();
21+
S_Siyaar.sleep();
22+
}
23+
}

‎Q13_SumAndSub_Pack.java‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//Q13. WAP to create a package Calc with methods Sum() & Sub() and show the Implementation in a class.
2+
package JAVA_Lab_File;
3+
4+
import Calc.Add;
5+
import Calc.Subtract;
6+
7+
import java.util.Scanner;
8+
9+
public class Q13_SumAndSub_Pack {
10+
public static void main(String[] args)
11+
{
12+
System.out.println("Sum ");
13+
System.out.println("Subtract ");
14+
15+
System.out.print("Enter your choice: ");
16+
Scanner sc = new Scanner(System.in);
17+
int t = sc.nextInt();
18+
switch (t) {
19+
case 1 -> {
20+
Add a = new Add();
21+
a.sum();
22+
}
23+
case 2 -> {
24+
Subtract s = new Subtract();
25+
s.subtract();
26+
}
27+
default -> System.out.println("invalid choice");
28+
}
29+
}
30+
}

‎Q14_Reverse_Num.java‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//Q14. WAP to print reverse of a given number.
2+
package JAVA_Lab_File;
3+
4+
import java.util.Scanner;
5+
6+
public class Q14_Reverse_Num {
7+
public static void main(String[] args) {
8+
Scanner sc = new Scanner(System.in);
9+
System.out.println("Enter a no. to reverse it: ");
10+
int num = sc.nextInt();
11+
int r_num=0;
12+
while(num>0)
13+
{
14+
r_num=(r_num*10)+(num%10);
15+
num=num/10;
16+
}
17+
System.out.println("Reversed: "+ r_num);
18+
}
19+
}

‎Q15_Single_catch.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Q15. WAP to show the working of a single Catch block.
2+
package JAVA_Lab_File;
3+
4+
public class Q15_Single_catch {
5+
public static void main(String[] args) {
6+
try{
7+
int a = 10;
8+
int b = 0;
9+
int c = a/b; // exception
10+
}catch(ArithmeticException e){
11+
System.out.println(e);
12+
}
13+
}
14+
}

‎Q16_Throw_and_Throws.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//Q16. WAP to show working of throw and throws for handling exceptions
2+
package JAVA_Lab_File;
3+
4+
import java.io.IOException;
5+
6+
public class Q16_Throw_and_Throws {
7+
8+
public static void main(String[] args) throws IOException {
9+
//declare exception
10+
Test.method();
11+
System.out.println("The Normal flow...");
12+
}
13+
}
14+
class Test {
15+
static void method()throws IOException
16+
{
17+
throw new IOException("Zaphkiel error");//checked exception
18+
}
19+
}
20+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /