Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

series

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

import java.util.

Scanner;
public class Fibonacci_Series
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.print("Enter the number of terms in Fibonacci:");
int count = s.nextInt();

int first_term=0;
int second_term=1;
for(int i = 1; i <= count; i++)
{
System.out.print(first_term + " ");
int next_term = first_term + second_term;
first_term = second_term;
second_term = next_term;
}
}
}

***************************************************************

import java.util.Scanner;
public class Palindrome_Number
{
public static void main(String args[])
{
int num,rem,temp,reverse = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number:");
num = s.nextInt();
temp=num;
while(num != 0)
{
rem = num % 10;
reverse = reverse * 10 + rem;
num = num / 10;
}
if(temp==reverse)
System.out.println("Given number is a Palindrome :"+reverse);
else
System.out.println("Given number is not a Palindrome");

}
}

____________________________________________________________________

//Program to Compute the Sum of Digits in a given Integer


import java.util.Scanner;
public class Digit_Sum
{
public static void main(String args[])
{
int num, rev, sum = 0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the number:");
num = s.nextInt();
while(num != 0)
{
rev = num % 10;
sum = sum + rev;
num = num / 10;
}
System.out.println("Sum of Digits:"+sum);
}
}

*****************************************************
import java.util.Scanner;
public class Multiplication_Table
{
public static void main(String[] args)
{
int min,max,i,j;
Scanner s = new Scanner(System.in);
System.out.print("Enter the min number:");
min=s.nextInt();
System.out.print("Enter the max number:");
max=s.nextInt();
for(int i=min; i <= max; i++)
{
for(int j=1; j <= 10; j++)
{
System.out.println("\n %d * %d = %d \n", i, j, i * j);
}
System.out.println("\n -------------------------");
}
}
}

*************************************************************************
import java.util.Scanner;
public class Equal_Integer{

public static void main(String[] args)


{
int m; int n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number:");
m = s.nextInt();
System.out.print("Enter the second number:");
n = s.nextInt();
if(m == n)
{
System.out.println(m+" and "+n+" are equal ");
}
else
{
System.out.println(m+" and "+n+" are not equal ");
}
}
}
**************************************************

import java.util.Scanner;
public class MatixMultiplication
{
public static void main(String args[])
{
int n;
Scanner input = new Scanner(System.in);
System.out.println("Enter the base of squared matrices");
n = input.nextInt();
int[][] a = new int[n][n];
int[][] b = new int[n][n];
int[][] c = new int[n][n];
System.out.println("Enter the elements of 1st martix row wise \n");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
a[i][j] = input.nextInt();
}
}
System.out.println("Enter the elements of 2nd martix row wise \n");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
b[i][j] = input.nextInt();
}
}
System.out.println("Multiplying the matrices...");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
for (int k = 0; k < n; k++)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
}
System.out.println("The product is:");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
System.out.print(c[i][j] + " ");
}
System.out.println();
}
input.close();
}
}
***********************

import java.util.Scanner;

public class CodesCracker


{
public static void main(String[] args)
{
int i, j, k, n,sum=0;

Scanner scan = new Scanner(System.in);


System.out.println("Enter the base of squared matrices");
n = scan.nextInt();

int[][] matrixOne = new int[n][n];


int[][] matrixTwo = new int[n][n];
int[][] matrixThree = new int[n][n];

System.out.println("Enter the elements of 1st martix row wise \n");


for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
matrixOne[i][j] = scan.nextInt();
}
}
System.out.println("Enter the elements of 2nd martix row wise \n");
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
matrixTwo[i][j] = scan.nextInt();
}
}

// multiplying the two matrices


System.out.println("Multiplying the matrices...");
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
sum = 0;
for(k=0; k<n; k++)
{
sum = sum + (matrixOne[i][k] * matrixTwo[k][j]);
}
matrixThree[i][j] = sum;
}
}

System.out.println("\nMultiplication Result of Two Matrices is:");


for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
System.out.print(matrixThree[i][j]+ " ");
}
System.out.println("\n");
}
}
}

**********************************************************************

import java.util.Scanner;

public class VowelCheck


{
public static void main(String[] args)
{
char ch;
Scanner scan = new Scanner(System.in);

System.out.print("Enter an Alphabet: ");


ch = scan.next().charAt(0);

if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' ||


ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
System.out.println("\nIt is a Vowel:" );
else
System.out.println("\nIt is a Consonant.");
}
}

************************************************

You might also like