How Do I Set or Change The PATH System Variable?
How Do I Set or Change The PATH System Variable?
How Do I Set or Change The PATH System Variable?
This will print the version of the java executable, if it can find it. If you get error java: Command not found. Then path
is not properly set.
To find out which java executable the first one found in your PATH, execute:
% which java
Programmes
1)Calculate Circle Area using Java Example
1. import java.io.BufferedReader;
2. import java.io.IOException;
3. import java.io.InputStreamReader;
4.
5. public class CalculateCircleAreaExample {
6.
7. public static void main(String[] args) {
8.
9. int radius = 0;
10. System.out.println("Please enter radius of a circle");
11.
12. try
13. {
14. //get the radius from console
15. BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
16. radius = Integer.parseInt(br.readLine());
17. }
18. //if invalid value was entered
19. catch(NumberFormatException ne)
20. {
21. System.out.println("Invalid radius value" + ne);
22. System.exit(0);
23. }
24. catch(IOException ioe)
25. {
26. System.out.println("IO Error :" + ioe);
27. System.exit(0);
28. }
29.
30. /*
31. * Area of a circle is
32. * pi * r * r
33. * where r is a radius of a circle.
34. */
35.
36. //NOTE : use Math.PI constant to get value of pi
37. double area = Math.PI * radius * radius;
38.
39. System.out.println("Area of a circle is " + area);
40. }
41. }
o/p
1. /*
2. Output of Calculate Circle Area using Java Example would be
3. Please enter radius of a circle
4. 19
5. Area of a circle is 1134.1149479459152
6. */
o/p
1. /*
2. Output of Calculate Circle Perimeter using Java Example would be
3. Please enter radius of a circle
4. 19
5. Perimeter of a circle is 119.38052083641213
6. */
o/p
1. /*
2. Output of the program would be
3. 1 is odd number.
4. 2 is even number.
5. 3 is odd number.
6. 4 is even number.
7. 5 is odd number.
8. 6 is even number.
9. 7 is odd number.
10. 8 is even number.
11. 9 is odd number.
12. 10 is even number.
13. */
13) Find absolute value of float, int, double and long using Math.abs
1. public class FindAbsoluteValueExample {
2.
3. public static void main(String[] args) {
4.
5. int i = 8;
6. int j = -5;
7.
8. /*
9. * To find absolute value of int, use
10. * static int abs(int i) method.
11. *
12. * It returns the same value if the agrument is non negative value,
otherwise
13. * negation of the negative value.
14. *
15. */
16.
17. System.out.println("Absolute value of " + i + " is :" + Math.abs(i));
18. System.out.println("Absolute value of " + j + " is :" + Math.abs(j));
19.
20. float f1 = 10.40f;
21. float f2 = -50.28f;
22.
23. /*
24. * To find absolute value of float, use
25. * static float abs(float f) method.
26. *
27. * It returns the same value if the agrument is non negative value,
otherwise
28. * negation of the negative value.
29. *
30. */
31. System.out.println("Absolute value of " + f1 + " is :" + Math.abs(f1));
32. System.out.println("Absolute value of " + f2 + " is :" + Math.abs(f2));
33.
34. double d1 = 43.324;
35. double d2 = -349.324;
36. /*
37. * To find absolute value of double, use
38. * static double abs(double d) method.
39. *
40. * It returns the same value if the agrument is non negative value,
otherwise
41. * negation of the negative value.
42. *
43. */
44. System.out.println("Absolute value of " + d1 + " is :" + Math.abs(d1));
45. System.out.println("Absolute value of " + d2 + " is :" + Math.abs(d2));
46.
47. long l1 = 34;
48. long l2 = -439;
49. /*
50. * To find absolute value of long, use
51. * static long abs(long l) method.
52. *
53. * It returns the same value if the agrument is non negative value,
otherwise
54. * negation of the negative value.
55. *
56. */
57. System.out.println("Absolute value of " + l1 + " is :" + Math.abs(l1));
58. System.out.println("Absolute value of " + l2 + " is :" + Math.abs(l2));
59.
60. }
61. }
62.
63. /*
64. Output would be
65. Absolute value of 8 is :8
66. Absolute value of -5 is :5
67. Absolute value of 10.4 is :10.4
68. Absolute value of -50.28 is :50.28
69. Absolute value of 43.324 is :43.324
70. Absolute value of -349.324 is :349.324
71. Absolute value of 34 is :34
72. Absolute value of -439 is :439
73. */
int intCounter = 0;
int total = 0;
int number;
int largest;
System.out.println("Enter number: ");
largest = input.nextInt();
total += largest;
}//end if
}//end while
class LargestValueTest
{
public void main(String args[])
{
LargestValue LargestValue1 = new LargestValue();//create object of LargestValue class to call
method
LargestValue1.determineLargestValue();//find the largest integer in 10
}//end main
}//end class