Music BGM
Music BGM
Music BGM
import java.util.Scanner;
class Mark
int regno;
String name;
double avg,total;
void getData()
regno=s.nextInt();
name=s.next();
for(int i=0;i<3;i++)
m[i]=s.nextInt();
void calculate()
total=0;
for(int i=0;i<3;i++)
total +=m[i];
avg=total /3;
}
void putData()
System.out.println("student name:"+name);
for(int i=0;i<3;i++)
System.out.println("Total:"+total);
System.out.println("Average:"+avg);
class Student
m1.getData();
m1.calculate();
m1.putData();
STUDENTGRADE
import java.util.Scanner;
class Mark
int regno;
String name;
double avg,total;
char grade;
void getData()
regno=s.nextInt();
name=s.next();
for(int i=0;i<3;i++)
m[i]=s.nextInt();
void calculate()
total=0;
for(int i=0;i<3;i++)
total +=m[i];
avg=total/3;
void grade()
//double percentage=((double)(total)/maxmark)*100;
if(avg>=90)
{
grade='O';
grade='A';
grade='B';
grade='C';
grade='D';
else
grade='F';
void putData()
for(int i=0;i<3;i++)
System.out.println("Total:"+total);
System.out.println("Average:"+avg);
System.out.println("Grade:"+grade);
class StudentGrade
m1.getData();
m1.calculate();
m1.grade();
m1.putData();
TEXTILES
import java.io.*;
class Textiles
int no,price,total,ch;
try
do
System.out.println("3. Exit");
ch=Integer.parseInt(in.readLine());
switch(ch)
case 1 :
no=Integer.parseInt(in.readLine());
price=Integer.parseInt(in.readLine());
total=no*price;
System.out.println("Totalprice:"+total);
break;
case 2 :
System.out.println("kids wear");
no=Integer.parseInt(in.readLine());
price=Integer.parseInt(in.readLine());
total=no*price;
System.out.println("Total price:"+total);
case 3 :
System.out.println("Exit");
while(ch!=3);
catch (Exception e)
{}
OUT PUT:
1.saree section
2.kidswear
3.exit
saree section
total price:598
1. saree section
2.kids wear
3. exit
kids wear
50
total price:150
1. saree section
2. kids wear
3. exit
exit
DISPLAYING
import java.io.*;
class Displaying
System.out.println("screen Display");
for(int i=1;i<=9;i++)
for(int j=1;j<=i;j++)
System.out.print(" ");
System.out.print(i);
System.out.print("\n");
}
OUT PUT:
Screen Displaying
22
333
4444
55555
666666
7777777
88888888
999999999
TESTMYEXCEPTION
import java.io.*;
import java.lang.Exception;
MyException(String Message)
super(Message);
int x=5,y=1000;
try
float z=(float)x/(float)y;
if(z<0.01)
catch(MyException e)
System.out.println("caught MyException");
System.out.println(e.getMessage());
finally
OUT PUT:
caught myexception
i am always here
THREAD METHOD
import java.io.*;
for(int i=1;i<=5;i++)
if(i==1)yield();
for(int j=1;j<=5;j++)
if(j==3)stop();
System.out.println("Exit fromB");
for(int k=1;k<=5;k++)
if(k==1)
try
sleep(1000);
catch(Exception e)
class ThreadMethod
A a=new A ();
B b=new B();
C c=new C();
a.start();
System.out.println("Start thread B");
b.start();
c.start();
} OUT PUT:
Start thread A
start thread B
exit from B
from thread B1
from thread B2
frome thread B3
start thread C
from thread C
from thread C
from thread C
from thread C
from thread C
exit from C
EVENT HANDLING
import java.awt.Graphics;
import java.awt.Frame;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
String txt1="";
String txt2="";
String txt3="";
Myframe(String title)
super(title);
setSize(200,150);
addWindowListener(this);
txt1="Window activated";
;
}
System.exit(0);
txt2="Window dectivated";
txt3="Window deiconified";
{
gp.drawRoundRect(15, 25, 90, 20, 10, 5);
mframe.setVisible(true);
Out Put:
Window deactivated
Window deiconified
KEYEVENT HANDLING
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
String txt="";
String txt1="";
String txt2="";
String txt3="";
int kcode;
char ch;
int drawnnumber;
addKeyListener(this);
requestFocus();
ch=ke.getKeyChar();
txt1 +=ch;
if (txt1.length()>25)
txt1="";
txt="Key Typed";
repaint();
kcode=ke.getKeyCode();
if (kcode == ke.VK_F1)
if (kcode == ke.VK_SHIFT)
txt="Key Pressed";
repaint();
txt="Key Released";
repaint();
gp.drawString(txt3, 20,80);
showStatus("Key events");
Out put:
Key presed
Key relesed
import java.applet.*;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.*;
String txt="Nothing";
addMouseListener(this);
addMouseMotionListener(this);
txt="mouse clicked";
repaint();
txt="mouse Exicted";
repaint();
txt="mouse Exited";
repaint();
txt="mouse pressed";
setForeground(Color.cyan);
repaint();
{
txt="mouse released";
setForeground(Color.cyan);
repaint();
txt="mouse Dragged";
setForeground(Color.red);
repaint();
txt="mouse Moved";
setForeground(Color.red);
repaint();
gp.drawString(txt,20,40);
Nothing
Mouse Exited
Mouse Presed
Mouse Dragged
Mouse clicked
Mouse Moved
JAVA APPLET
import java.awt.*;
import java.applet.*;
g.drawLine(500, 40,350,140);
g.drawLine(500, 40,650,140);
g.drawRect(350,140,300,100);
height=1000></applet>*/
Out put:
import java.awt.*;
import java.applet.*;
Image picture;
picture =getImage(getDocumentBase(),"Rabbit.jpeg");
for(int i=0;i<500;i++)
try
Thread.sleep(100);
catch(Exception e)
{}
height=1000></applet>*/
Out Put:
<html>
<head>
<script>
function p() {
var a, b,op,c;
a= document.myform.a.value;
a = parseInt(a)
b = document.myform.b.value;
b = parseInt(b)
op = document.myform.op.value;
op = parseInt(op)
if (op == 1) {
c=a+b
c=a-b
c=a*b
c=a/b
else if (op == 5) {
c=a % b
</script>
</head>
<body>
<center>
<h1>Arithmetic Operations</h1>
<hr color="Green">
<form name="myform">
<h4>1.Addition </h4>
<h4>2.Subtraction</h4>
<h4>3.Multiplication</h4>
<h4>4.Division </h4>
<h4>5.Modulus</h4>
Enter A value:
<br><br>
Enter B value:
<br><br>
<br><br>
<br>
</form>
</center>
</body>
</html>
Out put:
窗体顶端
1.Addition
2.Subtraction
3.Multiplication
4.Division
5.Modulus
Enter A value: 76
Enter B value: 88
Palindrome
<html>
</head>
<body>
<!-- Use JavaScript programming code to validate the Palindrome numbers or strings. -->
<script>
function validatePalin(str) {
}
}
console.log(value);
</script>
</body>
</html>
Out Put:
Anna is a palindrome
<html>
<head>
<title>
</title>
<script type="text/javascript">
function p() {
n = document.myform.n.value;
n = parseInt(n)
if (n % i == 0) {
flag = false;
break;
else
</script>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<hr color="Green">
<form name="myform">
<br><br>
<br>
</form>
</center>
</body>
</html>
Out put:
7 is a prime
<html>
<body>
<script>
return (a > b) ? a : b;
});
</script>
</body>
</html>
Out put:
Gui components
import java.awt.*;
import java.applet.*;
l1.setFont(f1);
add(t1);
add(l1);
add(l2);
add(l3);
add(l4);
add(c1);
add(c2);
add(ch1);
add(b1);
ch1.add("UG");
ch1.add("PG");
setLayout(null);
l1.setBounds(500,20,200,40);
t1.setBounds(500,60,100,20);
l2.setBounds(200,60,200,40);
l3.setBounds(200,100,200,40);
l4.setBounds(200,140,200,40);
c1.setBounds(500,90,200,50);
c2.setBounds(700,90,200,50);
ch1.setBounds(500,140,200,40);
b1.setBounds(500,300,80,40);
height=1000></applet>*/
Out Put:
Application form
Enter Applicant name: R.kiruthika
Course to join : Ug ^
Submit
FILE MANAGEMENT
import java.io.*;
class CopyCharacter
FileReader ins=null;
FileWriter outs=null;
try
int ch;
while( (ch=ins.read())!=-1)
outs.write(ch);
}
catch(IOException e)
System.out.println(e);
System.exit(- 1);
finally
try
ins.close();
outs.close();
Out Put:
Import javax.swing.*;
JFrame f;
FlowLayoutDemo()
{
f=new Jframe();
f.add(l1);
f.add(tf1);
f.add(b1);
f.SetSize(300,300);
f.SetVisible(true);
New FlowLayoutDemo()
Output: