Sunteți pe pagina 1din 9

Arithmetic

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.

System.out.println("d = " + d);


System.out.println("e = " + e);
}
}

. 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,

Marks of each subject)(Number of subjects varies for each student)

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

and class obtained.

Solution :-

import java.io.*;

class Student

static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

int rno,nofs,tot,per;

String sname,grade;

Student(int r,String s,int cnt)

rno=r;

sname=s;

nofs=cnt;

static void getMark(Student s[],int n) throws Exception

for(int i=0;i<n;i++)

System.out.println("Subject of Student :" + (i+1));

int mks[]=new int[s[i].nofs];

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";

else if(s[i].per>=60 && s[i].per <70)

s[i].grade="A";

else if (s[i].per >=50 && s[i].per <60)

s[i].grade="B";

else if (s[i].per >=40 && s[i].per < 50)

s[i].grade="C";

else

s[i].grade="Fail";

System.out.println("Rno" + "\t" + "Sname" + "\t" + "No Of Sub" + "\t" + "Total" + "\t"

+"Percentage" + "\t" +"Grade");

for(int i=0;i<n;i++)

s[i].disp();

void disp()

System.out.println( rno + "\t" + sname + "\t" +

"\t" +

grade);

nofs + "\t\t" +

tot + "\t\t" + per +

class Ass3

public static void main(String args[]) throws Exception

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("How Many Records");

int n=Integer.parseInt(br.readLine());

Student s[]=new Student[n];

for(int i=0;i<n;i++)

System.out.println("Enter the RollNo");

int r=Integer.parseInt(br.readLine());

System.out.println("Enter the Student Name");

String sn=br.readLine();

System.out.println("How Many Subject");

int cn=Integer.parseInt(br.readLine());

s[i]=new Student(r,sn,cn);

System.out.println("Student Details");

Student.getMark(s,n);

S-ar putea să vă placă și