0% found this document useful (0 votes)
3 views

Java Pgms

The document outlines a lab course for programming in Java, detailing course outcomes that include simple Java programs, decision making, inheritance, arrays, multi-threading, and exception handling. It provides examples of Java code for basic operations, decision-making with if-else statements, and switch-case constructs to determine the day of the week. The document also includes sample outputs for the provided Java programs.

Uploaded by

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

Java Pgms

The document outlines a lab course for programming in Java, detailing course outcomes that include simple Java programs, decision making, inheritance, arrays, multi-threading, and exception handling. It provides examples of Java code for basic operations, decision-making with if-else statements, and switch-case constructs to determine the day of the week. The document also includes sample outputs for the provided Java programs.

Uploaded by

gokulvarma985
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

XCI 506B - PROGRAMMING IN JAVA LAB

PROGRAMMING IN JAVA LAB L T P C


XCI 506B
0 0 2 2
C:P:A 0:1.5:0.5 L T P H
0 0 4 4
Course Outcomes Domain Level
60
1. Simple Java Programs
2. Decision Making, Branching and Looping
3. Constructors and Method Overloading
4. Inheritance and Method Overriding
5.Arrays and Strings
6. Interfaces and Packages
7.Multi Threading
8. Exception Handling
9. Applet Programming
10. Event Handling

//1.Simple java program

import java.util.Scanner;

class ex1

public static void main(String[] args)

Scanner s = new Scanner(System.in);

System.out.println("Enter two numbers:");

int a = s.nextInt();

int b = s.nextInt();

System.out.println("a="+a);
System.out.println("b="+b);

System.out.println("Sum="+(a+b));

System.out.println("Difference="+(a-b));

System.out.println("Product="+(a*b));

System.out.println("Quotient after division="+(a/b));

System.out.println("Remainder after division="+(a%b));

s.close();
}

OUTPUT

E:\Java_Pgms>javac ex1.java

E:\Java_Pgms>java ex1

Enter two numbers:

45

23

a=45

b=23

Sum=68

Difference=22

Product=1035

Quotient after division=1

Remainder after division=22

E:\Java_Pgms>
// 2.1 Decision making and branching
import java.util.Scanner;
class bigof3
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter three numbers:");
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
int big;
if ((a>b)&&(a>c))
big=a;
else if(b>c)
big=b;
else
big=c;
System.out.println("Big="+big);
s.close();
}
}
OUTPUT

E:\Java_Pgms>javac bigof3.java

E:\Java_Pgms>java bigof3

Enter three numbers:

45

23

32

a=45

b=23

c=32

Big=45

E:\Java_Pgms>

// 2.2 Decision making and branching

import java.util.Scanner;

class ex22
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);

System.out.print("Enter a number (1-7) to find the day of the week: ");


int day = s.nextInt();

switch (day) {
case 1:
System.out.println("Monday");
break;
case 2:
System.out.println("Tuesday");
break;
case 3:
System.out.println("Wednesday");
break;
case 4:
System.out.println("Thursday");
break;
case 5:
System.out.println("Friday");
break;
case 6:
System.out.println("Saturday");
break;
case 7:
System.out.println("Sunday");
break;
default:
System.out.println("Invalid input! Please enter a number between 1 and 7.");
}

s.close();
}
}

Example Output 1:

Enter a number (1-7) to find the day of the week: 3


Wednesday

Example Output 2:

Enter a number (1-7) to find the day of the week: 6


Saturday

Example Output 3 (Invalid Input):

Enter a number (1-7) to find the day of the week: 10


Invalid input! Please enter a number between 1 and 7.

You might also like