Unverified Commit 5eefb58a authored by Lokesh Singh's avatar Lokesh Singh Committed by GitHub

Add files via upload

parent 12c2112a
import java.util.Scanner;
// first method using if-else
public class checkNoisOddorEven {
static public void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number:");
int val = input.nextInt();
if (val % 2 == 0) {
// if((val | 1) > val)
// if (val & 1 == 1)
System.out.println("No. is even");
}
else {
System.out.println("No. is odd");
}
}
}
public class findFactorial {
static public int printFactorial(int n) {
if(n==0)
return 1;
return n * printFactorial(n-1);
}
static public int printFactorialIterative(int n) {
int res = 1;
for(int i = 2; i <= n; i++ ) {
res = res*i;
}
return res;
}
public static void main(String[] args) {
int factVal = 6;
int x = printFactorial(factVal);
System.out.println("factorial of "+ factVal +" is "+ x);
System.out.println(printFactorialIterative(factVal));
}
}
public class findLargestAmongThree {
static int largestOfThree(int a, int b, int c) {
// return Math.max(a, Math.max(b, c));
return a>b?(a>c?a:c):(b>c?b:c);
}
public static void main(String[] args) {
int a = 2;
int b = 5;
int c = 4;
int largest = 0;
if (a > b) {
largest = a;
} else if (b > c) {
largest = b;
} else {
largest = c;
}
System.out.println("Largest among three numbers is: " + largest);
System.out.println("Largest among three numbers is: " + largestOfThree(a, b, c));
}
}
public class helloworld {
public static void main(String[] arge) {
System.out.println("Hello, World!");
}
}
public class isLeapYear {
public static void main(String[] args) {
int year = 2020;
if (year % 4 == 0) {
System.out.println("Leap Year");
} else {
System.out.println("Not a Leap Year");
}
}
}
// java program to multiply two floating nos.
public class multiply {
public static void main(String[] args) {
float a = 2.5f;
float b = 3.5f;
float c = a * b;
System.out.println(c);
}
}
import java.util.Scanner;
public class readInput {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a number:");
int val = input.nextInt();
System.out.println(val);
}
}
// public class swapNo {
// public static void main(String[] args) {
// int a = 2;
// int b = 3;
// int temp;
// System.out.println("values of a and b before swaping: ");
// System.out.println("a: "+ a);
// System.out.println("b: "+ b);
// temp = a;
// a = b;
// b = temp;
// System.out.println("values of a and b after swaping: ");
// System.out.println("a:"+ a);
// System.out.println("b:"+ b);
// }
// }
// we will make seprate function for swapping
public class swapNo {
// static void swapValues(int a, int b) {
// int temp;
// temp = a;
// a = b;
// b = temp;
// swapValues(a, b);
// System.out.println("values of a and b after swaping:");
// System.out.println("a: " + a);
// System.out.println("b: " + b);
// }
static void swapWithoutTemp(int a, int b) {
a = a * b;
b = a / b;
a = a / b;
System.out.println("values of a and b after swaping:");
System.out.println("a: " + a);
System.out.println("b: " + b);
}
public static void main(String[] args) {
int a = 3;
int b = 8;
// swapValues(a, b);
swapWithoutTemp(a, b);
}
}
\ No newline at end of file
public class vowelOrConsonent {
public static void vowel_or_consonent(char y) {
if (y == 'a' || y == 'e' || y == 'i' || y =='o' || y == 'u') {
System.out.println("It is vowel");
} else {
System.out.println("It is consonent");
}
}
public static void main(String[] args) {
vowel_or_consonent('b');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment