- Write a program to print Hello World?
- Write a program to find area of circle?
- Write a program to find area of triangle?
- Write a program to convert rupees into dollar?
- Write a program to covert fahrenheit to celsius?
- Write a program to covert celsius to fahrenheit?
- Write a program to check a number is divisible by 2 or 3?
- Write a program to check a number is even?
- Write a program to check a number is odd?
- Write a program to check a number is power of 2?
- Write a program to find smallest number among 3 numbers?
- Write a program to check if a number is even or not using Ternary operator?
- Write a program to find factorial of a number?
- Write a program to check a number is prime?
- Write a program to print Fibonacci series?
- Write a program to print 500 to 600 using loop?
- Write a program to check a number is power of 2 using loops?
- Write a program to find HCF or GCF of two numbers?
- Write a program to print only odd numbers from 1000 to 2000?
- Create a method that accept a number and return factorial of the number?
- Create a method to check number is palindrome or not?
- Create a method to check number is prime or not?
- Create a method to check year is leap year or not?
- Create a method to print fibonacci series?
- Create a method to check number is power of 2?
- Create a method to find permutation of two number?
- Create a method to find combination of two number?
public class HelloWorld {
public static void main(String[] args) {
//Hello World!
System.out.println("Hello World!");
}
}
public static void main(String[] args) {
//Hello World!
System.out.println("Hello World!");
}
}
public class Circle {
public static void main(String[] args) {
double radius = 10.0, area;
area = 22.0 / 7.0 * radius *radius;
//Area of radius 10.0 is 314.2857142857143
System.out.println("Area of radius " + radius + " is " + area);
}
}
public static void main(String[] args) {
double radius = 10.0, area;
area = 22.0 / 7.0 * radius *radius;
//Area of radius 10.0 is 314.2857142857143
System.out.println("Area of radius " + radius + " is " + area);
}
}
public class Triangle {
public static void main(String[] args) {
double base = 10.5, height = 20.5;
double area = 0.5 * base * height;
System.out.println("Area of Triangle of Base " + base + " and Height " + height + " is " + area);
}
}
public static void main(String[] args) {
double base = 10.5, height = 20.5;
double area = 0.5 * base * height;
System.out.println("Area of Triangle of Base " + base + " and Height " + height + " is " + area);
}
}
import java.util.Scanner;
public class RupeesToDollars {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Amount in Indian Rupees (INR): ");
double rupees = sc.nextDouble();
double dollars;
dollars = rupees / 68.0;
System.out.println("₹" + rupees + " Indian Rupees in US Dollars is " + dollars + "$");
sc.close();
}
}
public class RupeesToDollars {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Amount in Indian Rupees (INR): ");
double rupees = sc.nextDouble();
double dollars;
dollars = rupees / 68.0;
System.out.println("₹" + rupees + " Indian Rupees in US Dollars is " + dollars + "$");
sc.close();
}
}
import java.util.Scanner;
public class FahrenheitToCelsius {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter fahrenheit value: ");
double fahrenheit = sc.nextDouble();
double celsius;
celsius = 5.0 / 9.0 * (fahrenheit - 32);
System.out.println(fahrenheit + " Fahrenheit (°F) to Celsius (°C) is " + celsius);
sc.close();
}
}
public class FahrenheitToCelsius {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter fahrenheit value: ");
double fahrenheit = sc.nextDouble();
double celsius;
celsius = 5.0 / 9.0 * (fahrenheit - 32);
System.out.println(fahrenheit + " Fahrenheit (°F) to Celsius (°C) is " + celsius);
sc.close();
}
}
import java.util.Scanner;
public class CelsiusToFahrenheit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Celsius value: ");
double celsius = sc.nextDouble();
double fahrenheit;
fahrenheit = 9.0 / 5.0 * celsius + 32;
System.out.println(celsius + " Celsius (°C) in Fahrenheit (°F) is " + fahrenheit);
sc.close();
}
}
public class CelsiusToFahrenheit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter Celsius value: ");
double celsius = sc.nextDouble();
double fahrenheit;
fahrenheit = 9.0 / 5.0 * celsius + 32;
System.out.println(celsius + " Celsius (°C) in Fahrenheit (°F) is " + fahrenheit);
sc.close();
}
}
public class Divisibility {
public static void main(String[] args) {
int num = 31;
if(num % 2 == 0 || num % 3 == 0){
System.out.println("Number " + num + " is divisible by 2 or 3");
} else {
System.out.println("Number " + num + " is not divisible by 2 or 3");
}
}
}
public static void main(String[] args) {
int num = 31;
if(num % 2 == 0 || num % 3 == 0){
System.out.println("Number " + num + " is divisible by 2 or 3");
} else {
System.out.println("Number " + num + " is not divisible by 2 or 3");
}
}
}
import java.util.Scanner;
public class Even {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
if (num % 2 == 0) {
System.out.println("Number " + num + " is even");
} else {
System.out.println("Number " + num + " is not even");
}
}
}
public class Even {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
if (num % 2 == 0) {
System.out.println("Number " + num + " is even");
} else {
System.out.println("Number " + num + " is not even");
}
}
}
import java.util.Scanner;
public class Odd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
if (num % 2 == 1) {
System.out.println("Number " + num + " is odd");
} else {
System.out.println("Number " + num + " is not odd");
}
sc.close();
}
}
public class Odd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
if (num % 2 == 1) {
System.out.println("Number " + num + " is odd");
} else {
System.out.println("Number " + num + " is not odd");
}
sc.close();
}
}
import java.util.Scanner;
public class PowerOf2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
if((num & num - 1)== 0){
System.out.println("Number " + num + " is power of 2");
} else {
System.out.println("Number " + num + " is not power of 2");
}
sc.close();
}
}
public class PowerOf2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
if((num & num - 1)== 0){
System.out.println("Number " + num + " is power of 2");
} else {
System.out.println("Number " + num + " is not power of 2");
}
sc.close();
}
}
import java.util.Scanner;
public class Smallest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number:");
int num1 = sc.nextInt();
System.out.println("Enter second number:");
int num2 = sc.nextInt();
System.out.println("Enter third number:");
int num3 = sc.nextInt();
if(num1 < num2 && num1 < num3) {
System.out.println(num1 + " is smallest");
} else if(num2 < num3) {
System.out.println(num2 + " is smallest");
} else {
System.out.println(num3 + " is smallest");
}
sc.close();
}
}
public class Smallest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number:");
int num1 = sc.nextInt();
System.out.println("Enter second number:");
int num2 = sc.nextInt();
System.out.println("Enter third number:");
int num3 = sc.nextInt();
if(num1 < num2 && num1 < num3) {
System.out.println(num1 + " is smallest");
} else if(num2 < num3) {
System.out.println(num2 + " is smallest");
} else {
System.out.println(num3 + " is smallest");
}
sc.close();
}
}
import java.util.Scanner;
public class EvenTernary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
String result = num % 2 == 0 ? "Number is even" : "Number is not even" ;
System.out.println(result);
sc.close();
}
}
public class EvenTernary {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
String result = num % 2 == 0 ? "Number is even" : "Number is not even" ;
System.out.println(result);
sc.close();
}
}
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
long fact = 1;
for (int i = 2; i <= num; i++) {
fact = fact * i;
}
System.out.println(num + "! is " + fact);
sc.close();
}
}
public class Factorial {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
long fact = 1;
for (int i = 2; i <= num; i++) {
fact = fact * i;
}
System.out.println(num + "! is " + fact);
sc.close();
}
}
import java.util.Scanner;
public class Prime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
boolean flag = true;
for (int i = 2; i <= num/2; i++) {
if(num % i == 0){
flag = false;
break;
}
}
if(flag) {
System.out.println(num + " is Prime Number");
} else {
System.out.println(num + " is not Prime Number");
}
sc.close();
}
}
public class Prime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
boolean flag = true;
for (int i = 2; i <= num/2; i++) {
if(num % i == 0){
flag = false;
break;
}
}
if(flag) {
System.out.println(num + " is Prime Number");
} else {
System.out.println(num + " is not Prime Number");
}
sc.close();
}
}
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter how many fibonacci series:");
int num = sc.nextInt();
int first = 0, second = 1, next;
System.out.print(first + " " + second + " ");
for (int i = 2; i <= num; i++) {
next = first + second;
System.out.print(next + " ");
first = second;
second = next;
}
sc.close();
}
}
public class Fibonacci {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter how many fibonacci series:");
int num = sc.nextInt();
int first = 0, second = 1, next;
System.out.print(first + " " + second + " ");
for (int i = 2; i <= num; i++) {
next = first + second;
System.out.print(next + " ");
first = second;
second = next;
}
sc.close();
}
}
public class Loops {
public static void main(String[] args) {
for (int n = 500; n <= 600; n++) {
System.out.println(n);
}
}
}
public static void main(String[] args) {
for (int n = 500; n <= 600; n++) {
System.out.println(n);
}
}
}
import java.util.Scanner;
public class PowerOfTwo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
int count = 0, temp = num;
while(temp > 0 && count <= 1){
if((temp & 0b1) == 1) {
count++;
}
temp = temp >> 1;
}
if(count == 1) {
System.out.println("Number " + num + " is power of 2");
} else {
System.out.println("Number " + num + " is not power of 2");
}
sc.close();
}
}
public class PowerOfTwo {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number:");
int num = sc.nextInt();
int count = 0, temp = num;
while(temp > 0 && count <= 1){
if((temp & 0b1) == 1) {
count++;
}
temp = temp >> 1;
}
if(count == 1) {
System.out.println("Number " + num + " is power of 2");
} else {
System.out.println("Number " + num + " is not power of 2");
}
sc.close();
}
}
import java.util.Scanner;
public class Gcd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number:");
int num1 = sc.nextInt();
System.out.println("Enter second number:");
int num2 = sc.nextInt();
int smaller = num1 < num2 ? num1 : num2;
while(smaller >= 1) {
if(num1 % smaller == 0 && num2 % smaller == 0) {
System.out.println("GCD of " + num1 + " and " + num2 + " is " + smaller);
break;
} else {
smaller--;
}
}
sc.close();
}
}
public class Gcd {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter first number:");
int num1 = sc.nextInt();
System.out.println("Enter second number:");
int num2 = sc.nextInt();
int smaller = num1 < num2 ? num1 : num2;
while(smaller >= 1) {
if(num1 % smaller == 0 && num2 % smaller == 0) {
System.out.println("GCD of " + num1 + " and " + num2 + " is " + smaller);
break;
} else {
smaller--;
}
}
sc.close();
}
}
public class Loop1 {
public static void main(String[] args) {
for (int i = 1000; i < 2000; i++) {
if(i % 2 == 1) {
System.out.print(i + " ");
}
}
}
}
public static void main(String[] args) {
for (int i = 1000; i < 2000; i++) {
if(i % 2 == 1) {
System.out.print(i + " ");
}
}
}
}
public static long factorial(int num) {
long fact = 1;
for (int n = 2; n <= num; n++) {
fact = fact * n;
}
return fact;
}
long fact = 1;
for (int n = 2; n <= num; n++) {
fact = fact * n;
}
return fact;
}
public boolean isPalindrome(int num) {
int temp = num, reverse = 0, remainder;
while(temp != 0) {
remainder = temp % 10;
reverse = reverse * 10 + remainder;
temp = temp / 10;
}
if(reverse == num) {
return true;
}
return false;
}
int temp = num, reverse = 0, remainder;
while(temp != 0) {
remainder = temp % 10;
reverse = reverse * 10 + remainder;
temp = temp / 10;
}
if(reverse == num) {
return true;
}
return false;
}
public boolean isPrime(int num) {
for(int i = 2; i <= (int)Math.sqrt(num); i++){
if(num % i == 0) {
return false;
}
}
return true;
}
for(int i = 2; i <= (int)Math.sqrt(num); i++){
if(num % i == 0) {
return false;
}
}
return true;
}
public boolean isLeapYear(int year) {
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
return true;
}
return false;
}
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
return true;
}
return false;
}
public void fibonacci(int count) {
int first = 0, second = 1, next;
System.out.print(first + " " + second + " ");
for (int i = 3; i <= count; i++) {
next = first + second;
System.out.print(next + " ");
first = second;
second = next;
}
}
int first = 0, second = 1, next;
System.out.print(first + " " + second + " ");
for (int i = 3; i <= count; i++) {
next = first + second;
System.out.print(next + " ");
first = second;
second = next;
}
}
public boolean isPowerOfTwo(int num) {
if((num & num - 1) == 0) {
return true;
}
return false;
}
if((num & num - 1) == 0) {
return true;
}
return false;
}
public static long permutation(int n, int r) {
long npr = 1;
for (int i = 0; i < r; i++) {
npr = npr * (n - i);
}
return npr;
}
long npr = 1;
for (int i = 0; i < r; i++) {
npr = npr * (n - i);
}
return npr;
}
public double combination(int n, int r) {
double ncr, numerator = 1, denominator = 1;
for (int i = 0; i < r; i++) {
numerator *= n - i;
}
for (int i = 1; i <= r; i++) {
denominator *= i;
}
ncr = numerator/denominator;
return ncr;
}
double ncr, numerator = 1, denominator = 1;
for (int i = 0; i < r; i++) {
numerator *= n - i;
}
for (int i = 1; i <= r; i++) {
denominator *= i;
}
ncr = numerator/denominator;
return ncr;
}
No comments:
Post a Comment