programme:- programme to create a class
import java.util.*;
public class student
{
int phy,chem,total,perc;
void getdata()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the marks of phy and chem");
phy=sc.nextInt();
chem=sc.nextInt();
}
void totaldata()
{
total=phy+chem;
System.out.println("total"+(total));
}
void percdata()
{
perc=(total)/3;
System.out.println("perc"+(perc));
}
void div()
{
if(perc>=65)
{
System.out.println("first divison");
}
}
}
This is a class programme now how we use this:we use this in other programme
1.)run the class programme in cmd by typing (javac student.java)
then use this class where you want
public class student1
{
public static void main(String args[])
{
student s=new student();
s.getdata();
s.totaldata();
s.percdata();
}
}
save this by student1.java
and run in cmd
1) javac student1.java
2) java student1
import java.util.*;
public class student
{
int phy,chem,total,perc;
void getdata()
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the marks of phy and chem");
phy=sc.nextInt();
chem=sc.nextInt();
}
void totaldata()
{
total=phy+chem;
System.out.println("total"+(total));
}
void percdata()
{
perc=(total)/3;
System.out.println("perc"+(perc));
}
void div()
{
if(perc>=65)
{
System.out.println("first divison");
}
}
}
This is a class programme now how we use this:we use this in other programme
1.)run the class programme in cmd by typing (javac student.java)
then use this class where you want
public class student1
{
public static void main(String args[])
{
student s=new student();
s.getdata();
s.totaldata();
s.percdata();
}
}
save this by student1.java
and run in cmd
1) javac student1.java
2) java student1
No comments:
Post a Comment