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

Java Progrmas

Uploaded by

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

Java Progrmas

Uploaded by

Kritika Saini
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

NAME: KRITIKA SAINI

I.D: VU1F2122094
EXP 3: DIV: B BATCH-A
Import java.util.Scanner;
class IfElse
{
public static void main(String[] args)
{
int marksObtained, passingMarks;
passingMarks = 40;
Scanner input = new Scanner(System.in);
System.out.println("Input marks scored by you");
marksObtained = input.nextInt();
if (marksObtained >= passingMarks) {
System.out.println("You passed the exam.");
}
else {
System.out.println("Unfortunately you failed to pass the exam.");
}}}

Output:
NAME: KRITIKA SAINI
I.D: VU1F2122094
EXP 5: DIV: B BATCH-A
import java.util.Scanner;
class Factorial
{
public static void main(String args[])
{
int n, c, fact = 1;
System.out.println("Enter an integer to calculate it's factorial");
Scanner in = new Scanner(System.in);
n = in.nextInt();
if ( n < 0 )
System.out.println("Number should be non-negative.");
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact*c;
System.out.println("Factorial of"+n+"is = "+fact);
}
}
}
Output:
NAME: KRITIKA SAINI
I.D: VU1F2122094
EXP 7: DIV: B BATCH-A
import java.util.Scanner;
class MultiplicationTable
{
public static void main(String args[])
{
int n, c;
System.out.println("Enter an integer to print it's multiplication table");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println("Multiplication table of "+n+" is :-");

for ( c = 1 ; c <= 10 ; c++ )


System.out.println(n+"*"+c+" = "+(n*c));
}
}
Output:
NAME: KRITIKA SAINI
I.D: VU1F2122094
DIV: B BATCH-A
EXP 11:
INPUT:
public class Main{
public static void main(String args[]){
String str1 = "visions";
String str2 = "developer";
String srt3 = str1+str2;
System.out.println(str3);
String str4 = str1.concat(str2);
System.out.println(str4);
}}

Output:
visionsdeveloper
visionsdeveloper
NAME: KRITIKA SAINI
I.D: VU1F2122094
EXP 12: DIV: B BATCH-A
public class MyOverloading {
public MyOverloading(){
System.out.println("Inside default constructor");
}
public MyOverloading(int i){
System.out.println("Inside single parameter constructor with int value");
}
public MyOverloading(String str)
{
System.out.println("Inside single parameter constructor with String object");
}
public MyOverloading(int i, int j)
{
System.out.println("Inside double parameter constructor");
}
public static void main(String a[])
{
MyOverloading mco = new MyOverloading();
MyOverloading spmco = new MyOverloading(10);
MyOverloading dpmco = new MyOverloading(10,20);
MyOverloading dpmco = new MyOverloading("java2novice");
}
}
Output:
Inside default constructor
Inside single parameter constructor with int value 10
Inside single parameter constructor with String object java2novice
Inside double parameter constructor 10, 20
NAME: KRITIKA SAINI
I.D: VU1F2122094
DIV: B BATCH-A
EXP 13:
INPUT:
class Sum
{ void add(int a, int b)
{ System.out.println("Sum of two="+(a+b)); }
void add(int a, int b,int c)
{ System.out.println("Sum of three="+(a+b+c));}}
class Polymorphism
{ public static void main(String args[])
{ Sum s=new Sum();
s.add(10,15);
s.add(10,20,30); }}

Output:-
Sum of two=25
Sum of three=60
NAME: KRITIKA SAINI
I.D: VU1F2122094
EXP 14: DIV: B BATCH-A
INPUT:
class Rectangle {
int length;
int breadth;
Rectangle(int len,int bre)
{
length = len;
breadth = bre;
}
}
class RectangleDemo {
public static void main(String args[]) {
Rectangle r1 = new Rectangle(20,10);
System.out.println("Length of Rectangle : " + r1.length);
System.out.println("Breadth of Rectangle : " + r1.breadth);
}
}
Output:
Length of Rectangle: 20
Breadth of Rectangle: 10
NAME: KRITIKA SAINI
I.D: VU1F2122094
EXP 15: DIV: B BATCH-A
/*class GrandParent
{
}*/
void fun()
{
System.out.println("Grand Parent class method Invoked");
}
interface Parent1
{
void fun();
}
class Parent2
{
void fun()
{
System.out.println("Parent2 class method Invoked");
}
}
class ChildTestMultipleInheritance1 extends Parent2 implements Parent1
{
public void fun()
{
super.fun();
System.out.println("Parent1 Interface method Invoked");
}
public static void main(String args[])
{
ChildTestMultipleInheritance1 c1=new ChildTestMultipleInheritance1()
c1.fun();
}
}

Output
Lower case String ==> all string function example in java
Upper case String ==> ALL STRING FUNCTION EXAMPLE IN JAVA
Length of the given string ==>35
String before trimming ==> String trimming example
String after trimming ==> String trimming example
Character at the index 6 is ==> r
String between index 3 to 9 is ==> Strin
String after replacement ==> All String function ExYmple in jYvY
String after replacement ==> All String function Example in loan
NAME: KRITIKA SAINI
I.D: VU1F2122094
EXP 16: DIV: B BATCH-A
importjava.io
class A extends Thread
{ public void run()
{System.out.println(“thread A started”);
for(int i=1;i<=2;i++)
{ System.out.println(“\From Thread A :i=”+i); }
System.out.println(“\Exit Thread A”); } }
class B extends Thread
{ public void run() {
System.out.println(“thread B started”);
for(int j=1;j<=2;j++)
{ System.out.println(“\From Thread B :j=”+j);}
System.out.println(“\Exit Thread B”); } }
class C extends Thread
{ public void run() {
System.out.println(“thread C started”);
for(int k=1;k<=2;k++)
{System.out.println(“\From Thread C :k=”+k);}
System.out.println(“\Exit Thread C”);}}
class MainThread
{ public static void main(String args[])
{ A t1=new A();
B t2=new B();
C t3=new C();
System.out.println(“Start thread A”);
t1.start();
System.out.println(“Start thread B”);
t2.start();
System.out.println(“Start thread C”);
t3.start();
System.out.println(“End of main thread”);}
Output:
start thread A
start thread B
start thread C
thread B started
from thread B : J=1
thread C started
from thread C : K=1
from thread C : K=2
exit from C
thread A started
from thread A : i=1
thread B started
from thread B : j=2
exit from B
thread A started
from thread B : i=2
exit from A
NAME: KRITIKA SAINI
I.D: VU1F2122094
EXP 17: DIV: B BATCH-A
Main.java
importjava.applet.*;
import java.awt.*;
public class Main extends Applet
{ public void paint(Graphics g)
{ g.drawString("Welcome in Java Applet.",40,20);}}

Main.html
<HTML>
<HEAD> </HEAD>
<BODY>
<div >
<APPLET CODE = "Main.class" WIDTH = "800" HEIGHT = "500"></APPLET>
</div>
</BODY> </HTML>
OUTPUT:

You might also like