first commit
This commit is contained in:
44
Calculator.java
Normal file
44
Calculator.java
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// Program that implements the arithmetic operation (Calculator) using switch statement.
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Calculator {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
char operator;
|
||||||
|
Double number1, number2, result;
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
System.out.println("Type the operator you want to use: +, -, *, or /");
|
||||||
|
operator = input.next().charAt(0);
|
||||||
|
System.out.println("Enter first number");
|
||||||
|
number1 = input.nextDouble();
|
||||||
|
System.out.println("Enter second number");
|
||||||
|
number2 = input.nextDouble();
|
||||||
|
switch (operator) {
|
||||||
|
case '+':
|
||||||
|
result = number1 + number2;
|
||||||
|
System.out.println(number1 + " + " + number2 + " = " + result);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '-':
|
||||||
|
result = number1 - number2;
|
||||||
|
System.out.println(number1 + " - " + number2 + " = " + result);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '*':
|
||||||
|
result = number1 * number2;
|
||||||
|
System.out.println(number1 + " * " + number2 + " = " + result);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '/':
|
||||||
|
result = number1 / number2;
|
||||||
|
System.out.println(number1 + " / " + number2 + " = " + result);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid operator!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
input.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
12
EvenOdd.java
Normal file
12
EvenOdd.java
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
// Program to find out the number entered is Even/Odd (Static Method).
|
||||||
|
|
||||||
|
public class EvenOdd {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num= 25;
|
||||||
|
System.out.println("You enter number: " + num);
|
||||||
|
if(num % 2 == 0)
|
||||||
|
System.out.println(num + " is even");
|
||||||
|
else
|
||||||
|
System.out.println(num + " is odd");
|
||||||
|
}
|
||||||
|
}
|
||||||
18
EvenOddDynamic.java
Normal file
18
EvenOddDynamic.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// Program to find out the number entered is Even/Odd (Dynamic Method).
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class EvenOddDynamic {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num;
|
||||||
|
System.out.println("Enter an Integer:");
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
num = input.nextInt();
|
||||||
|
if (num % 2 == 0) {
|
||||||
|
System.out.println("Entered number is even.");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Entered number is odd.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
FibonacciSeries.java
Normal file
21
FibonacciSeries.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// Program to generate fibonacci series upto n value (Dynamic Method).
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class FibonacciSeries {
|
||||||
|
public static void main(String args[]) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
int sum = 0, n;
|
||||||
|
int a = 0;
|
||||||
|
int b = 1;
|
||||||
|
System.out.println("Enter the nth value: ");
|
||||||
|
n = sc.nextInt();
|
||||||
|
System.out.println("Fibonacci series: ");
|
||||||
|
while(sum <= n) {
|
||||||
|
System.out.print(sum + " ");
|
||||||
|
a = b;
|
||||||
|
b = sum;
|
||||||
|
sum = a + b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
FibonacciSeriesStatic.java
Normal file
14
FibonacciSeriesStatic.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Program to generate fibonacci series upto n value (Static Method).
|
||||||
|
|
||||||
|
public class FibonacciSeriesStatic {
|
||||||
|
public static void main(String args[]) {
|
||||||
|
int n1=0,n2=1,n3,i,count=10;
|
||||||
|
System.out.print(n1+" "+n2);
|
||||||
|
for(i=2;i<count;++i) {
|
||||||
|
n3=n1+n2;
|
||||||
|
System.out.print(" "+n3);
|
||||||
|
n1=n2;
|
||||||
|
n2=n3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
HelloWorld.java
Normal file
9
HelloWorld.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// First program of any coding language is this only to print out on the screen "Hello World".
|
||||||
|
// So each step by step we will be moving on to the next level of coding in Java.
|
||||||
|
|
||||||
|
|
||||||
|
public class HelloWorld {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
201
LICENSE
Normal file
201
LICENSE
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
24
LargestNumber.java
Normal file
24
LargestNumber.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Program to find out the largest number (Dynamic Method).
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class LargestNumber {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int n, max;
|
||||||
|
Scanner s = new Scanner(System.in);
|
||||||
|
System.out.println("Enter the number of elements:");
|
||||||
|
n = s.nextInt();
|
||||||
|
int a[] = new int[n];
|
||||||
|
System.out.println("Enter the elements of the array:");
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
a[i] = s.nextInt();
|
||||||
|
}
|
||||||
|
max = a[0];
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (max < a[i]) {
|
||||||
|
max = a[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("Maximum value in this is: " + max);
|
||||||
|
}
|
||||||
|
}
|
||||||
15
LargestNumberStatic.java
Normal file
15
LargestNumberStatic.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
// Program to find out the largest number (Static Method).
|
||||||
|
|
||||||
|
public class LargestNumberStatic {
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
int num1 = 10, num2 = 20, num3 = 7;
|
||||||
|
if( num1 >= num2 && num1 >= num3)
|
||||||
|
System.out.println(num1+" is the largest Number");
|
||||||
|
|
||||||
|
else if (num2 >= num1 && num2 >= num3)
|
||||||
|
System.out.println(num2+" is the largest Number");
|
||||||
|
else
|
||||||
|
System.out.println(num3+" is the largest Number");
|
||||||
|
}
|
||||||
|
}
|
||||||
34
PrimeNo.java
Normal file
34
PrimeNo.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Program to display first n Prime number (Dynamic Method).
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class PrimeNo {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int n;
|
||||||
|
int status = 1;
|
||||||
|
int num = 3;
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
System.out.println("Enter the number of Prime numbers to be printed:");
|
||||||
|
n = scanner.nextInt();
|
||||||
|
if (n >= 1) {
|
||||||
|
System.out.println("First "+n+" prime numbers are:");
|
||||||
|
System.out.println(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( int i = 2 ; i <=n ; ) {
|
||||||
|
for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) {
|
||||||
|
if ( num%j == 0 )
|
||||||
|
{
|
||||||
|
status = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( status != 0 ) {
|
||||||
|
System.out.println(num);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
status = 1;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
PrimeNoStatic.java
Normal file
25
PrimeNoStatic.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Program to display first n Prime number (Static Method).
|
||||||
|
|
||||||
|
class PrimeNoStatic {
|
||||||
|
public static void main(String args[]) {
|
||||||
|
int n;
|
||||||
|
int status = 1;
|
||||||
|
int num = 3;
|
||||||
|
System.out.println("First 100 prime numbers are:");
|
||||||
|
System.out.println(2);
|
||||||
|
for ( int i = 2 ; i <=100 ; ) {
|
||||||
|
for ( int j = 2 ; j <= Math.sqrt(num) ; j++ ) {
|
||||||
|
if ( num%j == 0 ) {
|
||||||
|
status = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( status != 0 ) {
|
||||||
|
System.out.println(num);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
status = 1;
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
PrimeOrNot.java
Normal file
26
PrimeOrNot.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Program to find out whether the number is Prime or Not (Dynamic Method);
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class PrimeOrNot {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num, i = 2;
|
||||||
|
System.out.println("Enter the number: ");
|
||||||
|
Scanner s = new Scanner(System.in);
|
||||||
|
num = s.nextInt();
|
||||||
|
boolean flag = false;
|
||||||
|
while (i <= num / 2) {
|
||||||
|
if (num % i == 0) {
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
if (!flag) {
|
||||||
|
System.out.println(num + " is a prime number");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println(num + " is not a prime number");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
19
PrimeOrNotStatic.java
Normal file
19
PrimeOrNotStatic.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// Program to find out the prime or not (Static Method).
|
||||||
|
|
||||||
|
public class PrimeOrNotStatic {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int num = 29;
|
||||||
|
boolean flag = false;
|
||||||
|
for (int i = 2; i <= num / 2; ++i) {
|
||||||
|
if (num % i == 0) {
|
||||||
|
flag = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!flag)
|
||||||
|
System.out.println(num + " is a prime number.");
|
||||||
|
else
|
||||||
|
System.out.println(num + " is not a prime number.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
README.MD
Normal file
63
README.MD
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# JAVA Programs for everybody to try!
|
||||||
|
|
||||||
|
_`Last Updated: April 14' 2021`_
|
||||||
|
|
||||||
|
## Introduction:
|
||||||
|
|
||||||
|
Here are programs that every budding programmer who is learning to code in Java should start with.
|
||||||
|
These programs are a compilation of many different types of programs and levels of programming you should try.
|
||||||
|
If you want to start with levels of coding in mind use the table (serial) to refer which program is of which category.
|
||||||
|
If you want in which serial you should code rather than the levels then refer to table (levels) for a better understanding.
|
||||||
|
|
||||||
|
## Pre-Requisites:
|
||||||
|
|
||||||
|
1. A coding IDE or just use the CMD/Terminal on your Windows Pc/Mac respectively (I used VS Code for this).
|
||||||
|
|
||||||
|
2. Check that Java is properly installedin your system and the Path to Java is integratively set in your system.
|
||||||
|
|
||||||
|
3. Start by trying to create the program by yourself if you encounter any problems refer to the code in the program file,
|
||||||
|
if the problem still persist then create a issue or use Google/Stack Overlflow for help.
|
||||||
|
|
||||||
|
4. Done! You have successfully created the program in Java by your own.
|
||||||
|
|
||||||
|
## Serial:
|
||||||
|
|
||||||
|
|Serial No.|Program Name|Description of the program|
|
||||||
|
|----------|------------|--------------------------|
|
||||||
|
|1 | HelloWorld.java | Program to print out "Hello World" |
|
||||||
|
|2 | EvenOdd.java | Program to find out the number entered is Even/Odd (Static Method). |
|
||||||
|
|3 | EvenOddDynamic.java | Program to find out the number entered is Even/Odd (Dynamic Method). |
|
||||||
|
|4 | LargestNumberStatic.java | Program to find out the largest number (Static Method). |
|
||||||
|
|5 | LargestNumber.java | Program to find out the largest number (Dynamic Method). |
|
||||||
|
|6 | PrimeOrNotStatic.java | Program to find out the prime or not (Static Method). |
|
||||||
|
|7 | PrimeOrNot.java | Program to find out the prime or not (Dynamic Method). |
|
||||||
|
|8 | PrimeNoStatic.java | Program to display first n Prime number (Static Method). |
|
||||||
|
|9 | PrimeNo.java | Program to display first n Prime number (Dynamic Method). |
|
||||||
|
|10 | FibonacciSeriesStatic.java | Program to generate fibonacci series upto n value (Static Method). |
|
||||||
|
|11 | FibonacciSeries.java | Program to generate fibonacci series upto n value (Dynamic Method). |
|
||||||
|
|12 | RootsOfQuadracticEquationStatic.java | Program to find the root of quadratic equation (Static Method). |
|
||||||
|
|13 | RootsOfQuadracticEquation.java | Program to find the root of quadratic equation (Dynamic Method). |
|
||||||
|
|
||||||
|
|
||||||
|
## Levels:
|
||||||
|
|
||||||
|
|Level No.|Program Name|Description of the program|
|
||||||
|
|----------|------------|--------------------------|
|
||||||
|
|1 | HelloWorld.java | Program to print out "Hello World" |
|
||||||
|
|1 | EvenOdd.java | Program to find out the number entered is Even/Odd (Static Method). |
|
||||||
|
|1 | LargestNumberStatic.java | Program to find out the largest number (Static Method). |
|
||||||
|
|1 | PrimeOrNotStatic.java | Program to find out the prime or not (Static Method). |
|
||||||
|
|1 | PrimeNoStatic.java | Program to display first n Prime number (Static Method). |
|
||||||
|
|1 | FibonacciSeriesStatic.java | Program to generate fibonacci series upto n value (Static Method). |
|
||||||
|
|1 | RootsOfQuadracticEquationStatic.java | Program to find the root of quadratic equation (Static Method). |
|
||||||
|
|2 | EvenOddDynamic.java | Program to find out the number entered is Even/Odd (Dynamic Method). |
|
||||||
|
|2 | LargestNumber.java | Program to find out the largest number (Dynamic Method). |
|
||||||
|
|2 | PrimeOrNot.java | Program to find out the prime or not (Dynamic Method). |
|
||||||
|
|2 | PrimeNo.java | Program to display first n Prime number (Dynamic Method). |
|
||||||
|
|2 | FibonacciSeries.java | Program to generate fibonacci series upto n value (Dynamic Method). |
|
||||||
|
|2 | RootsOfQuadracticEquation.java | Program to find the root of quadratic equation (Dynamic Method). |
|
||||||
|
|
||||||
|
## [License]():
|
||||||
|
|
||||||
|
Copyright (c) 2021 PSMForums. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
25
RootsOfQuadraticEquation.java
Normal file
25
RootsOfQuadraticEquation.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Program to find the root of quadratic equation (Dynamic Method).
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class RootsOfQuadraticEquation {
|
||||||
|
public static void main(String args[]){
|
||||||
|
double secondRoot = 0, firstRoot = 0;
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.println("Enter the value of a :");
|
||||||
|
double a = sc.nextDouble();
|
||||||
|
System.out.println("Enter the value of b :");
|
||||||
|
double b = sc.nextDouble();
|
||||||
|
System.out.println("Enter the value of c :");
|
||||||
|
double c = sc.nextDouble();
|
||||||
|
double determinant = (b*b)-(4*a*c);
|
||||||
|
double sqrt = Math.sqrt(determinant);
|
||||||
|
if(determinant>0){
|
||||||
|
firstRoot = (-b + sqrt)/(2*a);
|
||||||
|
secondRoot = (-b - sqrt)/(2*a);
|
||||||
|
System.out.println("Roots are :: "+ firstRoot +" and "+secondRoot);
|
||||||
|
}else if(determinant == 0){
|
||||||
|
System.out.println("Root is :: "+(-b + sqrt)/(2*a));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
24
RootsOfQuadraticEquationStatic.java
Normal file
24
RootsOfQuadraticEquationStatic.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Program to find the root of quadratic equation (Static Method).
|
||||||
|
|
||||||
|
public class RootsOfQuadraticEquationStatic {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
double a = 2.3, b = 4, c = 5.6;
|
||||||
|
double root1, root2;
|
||||||
|
double determinant = b * b - 4 * a * c;
|
||||||
|
if (determinant > 0) {
|
||||||
|
root1 = (-b + Math.sqrt(determinant)) / (2 * a);
|
||||||
|
root2 = (-b - Math.sqrt(determinant)) / (2 * a);
|
||||||
|
System.out.format("root1 = %.2f and root2 = %.2f", root1, root2);
|
||||||
|
}
|
||||||
|
else if (determinant == 0) {
|
||||||
|
root1 = root2 = -b / (2 * a);
|
||||||
|
System.out.format("root1 = root2 = %.2f;", root1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
double real = -b / (2 * a);
|
||||||
|
double imaginary = Math.sqrt(-determinant) / (2 * a);
|
||||||
|
System.out.format("root1 = %.2f+%.2fi", real, imaginary);
|
||||||
|
System.out.format("\nroot2 = %.2f-%.2fi", real, imaginary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user