-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fca2c5
commit 2fe8057
Showing
9 changed files
with
353 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//a1q11 | ||
import java.util.*; | ||
public class Point | ||
{ | ||
int x, y; | ||
Point() | ||
{ | ||
x=0; | ||
y=0; | ||
} | ||
public void setPoint() | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Enter the Value of x :"); | ||
x=in.nextInt(); | ||
System.out.print("Enter the Value of y :"); | ||
y=in.nextInt(); | ||
} | ||
public void findDistance(Point ob1, Point ob2) | ||
{ | ||
int x1=ob1.x; | ||
int y1=ob1.y; | ||
int x2=ob2.x; | ||
int y2=ob2.y; | ||
double d=(x2-x1)*(x2-x1)+(y2-y2)*(y2-y1); | ||
d=Math.sqrt(d); | ||
System.out.println("Distance between the points = "+d); | ||
} | ||
public static void main(String args[]) | ||
{ | ||
Point ob1 = new Point(); | ||
Point ob2 = new Point(); | ||
Point ob = new Point(); | ||
ob1.setPoint(); | ||
ob2.setPoint(); | ||
ob.findDistance(ob1, ob2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//a1q9 | ||
import java.util.*; | ||
class Student | ||
{ | ||
String name; | ||
int roll, marks; | ||
Student() | ||
{ | ||
name=""; | ||
roll=0; | ||
marks=0; | ||
} | ||
public void setData() | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Name :"); | ||
name=in.nextLine(); | ||
System.out.print("Roll Number :"); | ||
roll=in.nextInt(); | ||
System.out.print("Marks :"); | ||
marks=in.nextInt(); | ||
} | ||
public void display() | ||
{ | ||
System.out.println("Name = "+name); | ||
System.out.println("Roll Number = "+roll); | ||
System.out.println("Marks = "+marks); | ||
} | ||
} | ||
public class StudentDetails | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Student ob1 = new Student(); | ||
Student ob2 = new Student(); | ||
Student ob3 = new Student(); | ||
ob1.setData(); | ||
ob2.setData(); | ||
ob3.setData(); | ||
ob1.display(); | ||
ob2.display(); | ||
ob3.display(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//a1q10 | ||
class Student2 | ||
{ | ||
String name; | ||
int roll, marks; | ||
public void setData() | ||
{ | ||
name=""; | ||
roll=0; | ||
marks=0; | ||
} | ||
public void setData(String s, int i, int j) | ||
{ | ||
name=s; | ||
roll=i; | ||
marks=j; | ||
} | ||
public void display() | ||
{ | ||
System.out.println("Name = "+name); | ||
System.out.println("Roll Number = "+roll); | ||
System.out.println("Marks = "+marks); | ||
} | ||
} | ||
public class StudentDetails2 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Student2 ob1 = new Student2(); | ||
Student2 ob2 = new Student2(); | ||
Student2 ob3 = new Student2(); | ||
ob1.setData(); | ||
ob2.setData("Marty",16,100); | ||
ob3.setData("Aradhya",15,95); | ||
ob1.display(); | ||
ob2.display(); | ||
ob3.display(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//a1q12 | ||
import java.util.*; | ||
class flower | ||
{ | ||
String name; | ||
int n; | ||
float price; | ||
public void setFlowerName() | ||
{ | ||
name=""; | ||
} | ||
public void setFlowerName(String s) | ||
{ | ||
name=s; | ||
} | ||
public void setPetalNumber() | ||
{ | ||
n=0; | ||
} | ||
public void setPetalNumber(int i) | ||
{ | ||
n=i; | ||
} | ||
public void setPrice() | ||
{ | ||
price=0.0f; | ||
} | ||
public void setPrice(float p) | ||
{ | ||
price=p; | ||
} | ||
public String getFlowerName() | ||
{ | ||
return name; | ||
} | ||
public int getPetalNumber() | ||
{ | ||
return n; | ||
} | ||
public float getPrice() | ||
{ | ||
return price; | ||
} | ||
} | ||
public class a1q12 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
flower ob1 = new flower(); | ||
flower ob2 = new flower(); | ||
System.out.println("Enter the Flower\'s Name : "); | ||
ob1.setFlowerName(in.nextLine()); | ||
System.out.println("Enter the Flower\'s number of Petals : "); | ||
ob1.setPetalNumber(in.nextInt()); | ||
System.out.println("Enter the Flower\'s Price : "); | ||
ob1.setPrice(in.nextFloat()); | ||
System.out.println("Name of Flower : "+ob1.getFlowerName()); | ||
System.out.println("Number of Petals is the Flower : "+ob1.getPetalNumber()); | ||
System.out.println("Price of Flower : "+ob1.getPrice()); | ||
ob2.setFlowerName(); | ||
ob2.setPetalNumber(); | ||
ob2.setPrice(); | ||
System.out.println("Name of Flower : "+ob2.getFlowerName()); | ||
System.out.println("Number of Petals is the Flower : "+ob2.getPetalNumber()); | ||
System.out.println("Price of Flower : "+ob2.getPrice()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.util.*; | ||
class a1q4 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
ArrayList<String> arr = new ArrayList<String>(); | ||
System.out.println("Start adding Sentences :"); | ||
for(int i=0; ; i++) | ||
{ | ||
String s=in.nextLine(); | ||
if(s.equals("")) | ||
{ | ||
break; | ||
} | ||
else | ||
{ | ||
arr.add(s); | ||
} | ||
} | ||
System.out.println("Printing the Sentences in Reverse order"); | ||
for(int i=arr.size()-1; i>=0; i--) | ||
{ | ||
System.out.println(arr.get(i)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.util.*; | ||
class a1q5 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
a1q5 ob = new a1q5(); | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Enter the number :"); | ||
boolean k=ob.isEven(in.nextInt()); | ||
if(k) | ||
{ | ||
System.out.println("The numbe is Even"); | ||
} | ||
else | ||
{ | ||
System.out.println("The numbe is odd"); | ||
} | ||
} | ||
public boolean isEven(int n) | ||
{ | ||
boolean k = true; | ||
|
||
for (int i = 1; i <= n; i++) | ||
k = !k; | ||
|
||
return k; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import java.util.*; | ||
class a1q6 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Enter the Length of array :"); | ||
int n=in.nextInt(); | ||
int arr[] = new int[n]; | ||
for(int a=0; a<arr.length; a++) | ||
{ | ||
System.out.print("arr["+a+"]="); | ||
arr[a]=in.nextInt(); | ||
} | ||
a1q6 ob = new a1q6(); | ||
System.out.println("Largest Element is "+ob.largest(arr)); | ||
System.out.println("Smallest Element is "+ob.smallest(arr)); | ||
} | ||
public int largest(int arr[]) | ||
{ | ||
int n=arr[0]; | ||
for(int a=1; a<arr.length; a++) | ||
{ | ||
if(n<arr[a]) | ||
{ | ||
n=arr[a]; | ||
} | ||
} | ||
return n; | ||
} | ||
public int smallest(int arr[]) | ||
{ | ||
int n=arr[0]; | ||
for(int a=1; a<arr.length; a++) | ||
{ | ||
if(n>arr[a]) | ||
{ | ||
n=arr[a]; | ||
} | ||
} | ||
return n; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import java.util.Scanner; | ||
class a1q7 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Enter the Length of array :"); | ||
int n=in.nextInt(); | ||
int arr[] = new int[n]; | ||
for(int a=0; a<arr.length; a++) | ||
{ | ||
System.out.print("arr["+a+"]="); | ||
arr[a]=in.nextInt(); | ||
} | ||
a1q7 ob = new a1q7(); | ||
ob.findOddPair(arr); | ||
} | ||
public void findOddPair(int arr[]) | ||
{ | ||
for(int a=0; a<arr.length-1; a++) | ||
{ | ||
for(int b=a; b<arr.length; b++) | ||
{ | ||
if(isOdd(arr[a]*arr[b])) | ||
{ | ||
System.out.println(arr[a]+" , "+arr[b]); | ||
} | ||
} | ||
} | ||
} | ||
public boolean isOdd(int i) | ||
{ | ||
return i%2==1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import java.util.*; | ||
class a1q8 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Enter the Length of array :"); | ||
int n=in.nextInt(); | ||
int p[] = new int[n]; | ||
int q[] = new int[n]; | ||
int r[] = new int[n]; | ||
for(int a=0; a<p.length; a++) | ||
{ | ||
System.out.print("p["+a+"]="); | ||
p[a]=in.nextInt(); | ||
} | ||
for(int a=0; a<q.length; a++) | ||
{ | ||
System.out.print("q["+a+"]="); | ||
q[a]=in.nextInt(); | ||
} | ||
System.out.println("p[i] X q[i] = r[i]"); | ||
for(int a=0; a<n; a++) | ||
{ | ||
r[a]=p[a]*q[a]; | ||
System.out.println("r["+a+"]="+r[a]); | ||
} | ||
} | ||
} |