Skip to content

Commit b4b1193

Browse files
author
mayurtanna
committed
First Commit
0 parents  commit b4b1193

11 files changed

+155
-0
lines changed

.classpath

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>JavaTest</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.7
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.7

bin/com/test/Point.class

360 Bytes
Binary file not shown.

bin/com/test/Question1.class

1.8 KB
Binary file not shown.

bin/com/test/Question2.class

1.38 KB
Binary file not shown.

bin/com/test/Question3.class

1.16 KB
Binary file not shown.

src/com/test/Question1.java

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.test;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Question1 {
7+
public static void main(String[] args) {
8+
9+
List<Point> points = new ArrayList<Point>();
10+
points.add(new Point(-1,0));
11+
points.add(new Point(2,2));
12+
points.add(new Point(1,3));
13+
14+
printBounds(points);
15+
16+
}
17+
18+
public static void printBounds(List<Point> points) {
19+
20+
int smallestX = points.get(0).x;
21+
int largestY = points.get(0).y;
22+
int[] smallestXs = new int[2];
23+
int[] largestYs = new int[2];
24+
25+
smallestXs[0] = smallestX;
26+
largestYs[0] = largestY;
27+
28+
for(int i=0; i< points.size(); i++)
29+
{
30+
31+
if(points.get(i).x < smallestX) {
32+
smallestXs[0] = points.get(i).x;
33+
smallestXs[1] = smallestXs[0];
34+
}
35+
if(points.get(i).y > largestY) {
36+
largestYs[1] = largestYs[0];
37+
largestYs[0] = points.get(i).y;
38+
39+
}
40+
System.out.println(""+largestYs[0] +","+ largestYs[1] );
41+
}
42+
43+
System.out.println("Bottom -left"+smallestXs[0] +","+ smallestXs[1] );
44+
System.out.println("Top-right"+largestYs[0] +","+ largestYs[1] );
45+
}
46+
47+
48+
}
49+
50+
class Point {
51+
int x, y;
52+
53+
Point(int x, int y) {
54+
this.x = x;
55+
this.y = y;
56+
}
57+
}

src/com/test/Question2.class

774 Bytes
Binary file not shown.

src/com/test/Question2.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.test;
2+
3+
public class Question2 {
4+
public static void main(String[] args) {
5+
6+
int red = 68;
7+
int green = 58;
8+
int blue =197;
9+
10+
11+
convertToHex(red,green,blue);
12+
13+
}
14+
15+
public static String convertToHex(int red, int green, int blue) {
16+
17+
StringBuilder hexCode = new StringBuilder("#");
18+
19+
try {
20+
21+
22+
String redHex = Integer.toHexString(red);
23+
String greenHex = Integer.toHexString(green);
24+
String blueHex = Integer.toHexString(blue);
25+
26+
hexCode.append(redHex);
27+
hexCode.append(greenHex);
28+
hexCode.append(blueHex);
29+
System.out.println(hexCode);
30+
} catch (Exception e) {
31+
System.out.print("Error" + e.getMessage());
32+
}
33+
return hexCode.toString();
34+
}
35+
36+
}

src/com/test/Question3.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.test;
2+
3+
public class Question3 {
4+
public static void main(String[] array) {
5+
int[] values = { 8, 6, 6, 20, 9, 1, 12, 16, 3, 16, 22, 2 };
6+
7+
int length = values.length;
8+
9+
for (int i = 0; i < values.length; i++) {
10+
int count =0;
11+
for(int j=0;j<values.length;j++) {
12+
13+
if(values[j]<=values[i]) {
14+
count++;
15+
}
16+
17+
}
18+
int percentile = count*100 / length;
19+
20+
System.out.println(percentile +" % of the numbers are less than or equal to "+values[i]);
21+
22+
}
23+
24+
25+
26+
}
27+
28+
}

0 commit comments

Comments
 (0)