Documente Academic
Documente Profesional
Documente Cultură
1. package operatorsdemo;
2. public class ArithmeticOperatorDemo {
3.
4. // Demonstrate the basic arithmetic operators.
5.
6.
public static void main(String args[]) {
7.
8.
// arithmetic using integers
9.
10.
System.out.println("Integer Arithmetic");
11.
12.
int i = 1 + 1;
13.
14.
int n = i * 3;
15.
16.
int m = n / 4;
17.
18.
int p = m - i;
19.
20.
int q = -p;
21.
22.
System.out.println("i = " + i);
23.
24.
System.out.println("n = " + n);
25.
26.
System.out.println("m = " + m);
27.
28.
System.out.println("p = " + p);
29.
30.
System.out.println("q = " + q);
31.
32.
// arithmetic using doubles
33.
34.
System.out.println("\nFloating Point Arithmetic");
35.
36.
double a = 1 + 1;
37.
38.
double b = a * 3;
39.
40.
double c = b / 4;
41.
42.
double d = c - a;
43.
44.
double e = -d;
45.
46.
System.out.println("a = " + a);
47.
48.
System.out.println("b = " + b);
49.
50.
System.out.println("c = " + c);
51.
52.
53.
54.
55.
56.
57.
58.
. Write a program to calculate the area of a Rectangle , a Circle & a Square using
pameterised constructor using BufferedReader class object.
*/
import java.io.*;
class area{
double a,b,rar,car,sar;
area(double x,double y){
a=x;
b=y;
}
void rectAr(){
rar=a*b;
System.out.println("Rectangle area: "+rar);
}
void circleAr(){
car=3.14*a*a;
System.out.println("Circle area: "+car);
}
void squareAr(){
sar=a*a;
System.out.println("Square area: "+sar);
}
}
public class as7 {
public static void main(String arg[]){
String s1,s2;
double d1,d2;
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Give the Dimension");
s1=br.readLine();
s2=br.readLine();
d1=Double.parseDouble(s1);
d2=Double.parseDouble(s2);
area ob=new area(d1,d2);
ob.rectAr();
ob.circleAr();
ob.squareAr();
}
catch(Exception e){
System.out.println(e);
}
}
}
/*Output:
Give the Dimension
10
20
Rectangle area: 200.0
Circle area: 314.0
Square area: 100.0
*/
Write a java program which creates class Student (Rollno, Name,- Number of subjects,
Write a parameterized constructor which initializes roll no, name & Number of subjects and
create the array of marks dynamically. Display the details of all students with percentage
Solution :-
import java.io.*;
class Student
int rno,nofs,tot,per;
String sname,grade;
rno=r;
sname=s;
nofs=cnt;
for(int i=0;i<n;i++)
for(int j=0;j<s[i].nofs;j++)
System.out.println("Marks");
mks[j]=Integer.parseInt(br.readLine());
s[i].tot=s[i].tot+mks[j];
s[i].per=s[i].tot/s[i].nofs;
if(s[i].per>=70)
s[i].grade="Dist";
s[i].grade="A";
s[i].grade="B";
s[i].grade="C";
else
s[i].grade="Fail";
for(int i=0;i<n;i++)
s[i].disp();
void disp()
"\t" +
grade);
nofs + "\t\t" +
class Ass3
int n=Integer.parseInt(br.readLine());
for(int i=0;i<n;i++)
int r=Integer.parseInt(br.readLine());
String sn=br.readLine();
int cn=Integer.parseInt(br.readLine());
s[i]=new Student(r,sn,cn);
System.out.println("Student Details");
Student.getMark(s,n);