For loop task
For loop task
For loop task
12) 2^2+4^2+6^2+...........+n^2
import java.util.Scanner;
public class angle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = sc.nextInt();
int sum=0;
for(int i=1;i<=n;i++){
if(i%2==0)
sum+=i * i;
}
13) 1^2+3^2+5^2+...........+n^2
import java.util.Scanner;
public class angle {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = sc.nextInt();
int sum=0;
for(int i=1;i<=n;i++){
if(i%2!=0)
sum+=i * i;
}
15) 1/1^2+1/2^2+1/3^2+.......+1/n^2.
import java.util.Scanner;
public class angle {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = scanner.nextInt();
double sum = 0.0;
for (int i = 1; i <= n; i++) {
sum += 1.0 / (i * i);
}
System.out.println("The sum of the series is: " + sum);
}
}
16) 1/1^2+1/3^2+1/5^2+.......+1/n^2.
import java.util.Scanner;
public class angle {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = scanner.nextInt();
double sum = 0.0;
for (int i = 1; i <= n; i++) {
if(i%2!=0)
sum += 1.0 / (i * i);
}
System.out.println("The sum of the series is: " + sum);
}
}
17.1/2^2+1/4^2+1/6^2+.......+1/n^2
import java.util.Scanner;
public class angle {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = scanner.nextInt();
double sum = 0.0;
for (int i = 1; i <= n; i++) {
if(i%2==0)
sum += 1.0 / (i * i);
}
System.out.println("The sum of the series is: " + sum);
}
}
19) 1!+2!+3!+......n!
import java.util.Scanner;
class angle{
public static void main(String args[]){
int i,fact=1;
int number=5;
int sum=0;
for(i=1;i<=number;i++){
fact=fact*i;
sum+=fact;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
}
20) 1!+3!+5!+......n!
import java.util.Scanner;
class angle{
public static void main(String args[]){
int i,fact=1;
int number=5;
int sum=0;
for(i=1;i<=number;i++){
fact=fact*i;
if(i%2!=0)
sum+=fact;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
}
21 )2!+4!+6!+......n!
import java.util.Scanner;
class angle{
public static void main(String args[]){
int i,fact=1;
int number=5;
int sum=0;
for(i=1;i<=number;i++){
fact=fact*i;
if(i%2==0)
sum+=fact;
}
System.out.println("Factorial of "+number+" is: "+fact);
}
}
22) 1/1!+1/2!+1/3!+.........1/n!
import java.util.Scanner;
class Angle {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int number = sc.nextInt();
double sum = 0.0;
int fact = 1;
23) 1/1!+1/3!+1/5!+.........1/n!
import java.util.Scanner;
class Angle {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int number = sc.nextInt();
24) 1/2!+1/4!+1/6!+.........1/n!
import java.util.Scanner;
class Angle {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int number = sc.nextInt();
27)multiplication
class angle {
public static void main(String[] args) {
int num = 5;
for (int i = 1; i <=10; i++) {
System.out.println(i +" * " + num +" = "+num * i);
}
}
}
28.Reverse'snumber
public class ReverseNumberExample1
int reverse = 0;
31)palindrome
public class ReverseNumberExample1
int reverse = 0;
} if (originalNumber == reversedNumber) {
} else {
}
}
32)Armstrong number:
import java.util.Scanner;
if (sum == originalNumber) {
System.out.println(originalNumber + " is an Armstrong number.");
} else {
System.out.println(originalNumber + " is not an Armstrong
number.");
}
scanner.close();
}
}
33)adam number
import java.util.Scanner;
int reversed = 0;
int originalNumber = number;
if (squareOriginal == reversedSquare) {
System.out.println(originalNumber + " is an Adam number.");
} else {
System.out.println(originalNumber + " is not an Adam number.");
}
}
}
int sum = 0;
if (sum == number) {
System.out.println(number + " is a perfect number.");
} else {
System.out.println(number + " is not a perfect number.");
}
scanner.close();
}
}
import java.io.*;
class hexa {
public static void main(String[] args) {
int n = 37;
String octal = "";
for (; n > 0; n = n / 8) {
octal = (n % 8) + octal;
}
System.out.println(octal);
}
}
class hexa{
public static void main(String[] args) {
int n = 37;
String hex = "";
System.out.println(hex);
}
}
class hexa {
public static void main(String[] args) {
String binary = "10101";
int decimal = 0;
int base = 1;
import java.io.*;
class hexa{
public static void main(String[] args) {
String binary = "10101";
int decimal = 0;
int base = 1;
import java.io.*;
class hexa{
public static void main(String[] args) {
String binary = "10101";
int decimal = 0;
int base = 1;
import java.io.*;
class hexa{
public static void main(String[] args) {
String octal = "25";
int decimal = 0;
int base = 1;
import java.io.*;
class hexa {
public static void main(String[] args) {
String octal = "25";
int decimal = 0;
int base = 1;
import java.io.*;
class hexa {
public static void main(String[] args) {
String octal = "25";
int decimal = 0;
int base = 1;
import java.io.*;
class hexa {
public static void main(String[] args) {
String hex = "25";
int decimal = 0;
int base = 1;
import java.io.*;
class hexa {
public static void main(String[] args) {
String hex = "25";
int decimal = 0;
int base = 1;
for (int i = hex.length() - 1; i >= 0; i--) {
int digit = hex.charAt(i) >= 'A' ? hex.charAt(i) - 'A' + 10 :
hex.charAt(i) - '0';
decimal += digit * base;
base *= 16;
}
import java.io.*;
class hexa {
public static void main(String[] args) {
String hex = "25";
int decimal = 0;
int base = 1;
1. Fibonacci Series
public class FibonacciSeries {
public static void main(String[] args) {
int n = 10; // Number of terms
int a = 0, b = 1;
2. Pell Series
public class PellSeries {
public static void main(String[] args) {
int n = 10; // Number of terms
int p0 = 0, p1 = 1;
3. Convert Time
i. Hour to Seconds
java
Copy code
public class TimeConversion {
public static void main(String[] args) {
int minutes = 120; // Example minutes
int hours = 0;
java
Copy code
public class TimeConversion {
public static void main(String[] args) {
int seconds = 3600; // Example seconds
int minutes = 0;
// Calculate the number with the first digit in the last place and the last digit in the first place
num1 = lastDigit * powerOfTen;
num2 = x / 10; // Remove the last digit
num3 = num2 / 10 * 10; // Remove the first digit and add it at the end
num3 = num1 + num3;
num4 = x % powerOfTen; // Get the middle part of the number
if (n > 0) {
System.out.println("The number is positive.");
} else if (n < 0) {
System.out.println("The number is negative.");
} else {
System.out.println("The number is zero.");
}
}
}