Saturday, January 30, 2016

JAVA Programs in Interview

In This Post we will discuss basic java programs .Interviewer want to test your programming skills and way of writing your stranded code in logical way.I had already post frequently asked java program is to find prime numbers between 1 to 100 .Some of the java programs we will discuss in this post.These Programs are fundamental  java programs,therefore before face java technical Round brush up these programs specially for beginners. These will get nervous feeling while facing interviews.lack of confidence in programming.So, I am writing frequently asked java programs in interview chamber. Let's start friends!!





Program 1: Java program to find whether the given number is palindrome or not


palindrome: A number is palindrome if and only if  the sequence of characters which reads the same forward and reverse directions is called as palindrome number.

Ex:  


Source Code:

import java.util.*;
class PalindromeDemo{
public static void main (String args[])
{
int reverse=0,rem;
int number=Integer.parseInt(args[0]);
int n=number;//here we are using n variable to check  last time to check
while(number>0)
{
rem=number%10;
reverse=reverse*10+rem;
number=number/10;
}
if(reverse==n)
{
System.out.println("The given number is palindrome");
}
else
{
System.out.println("The given number is not palindrome");
}
}

output:






Program 2: Java Program To Print Fibonacci Series of given number

Definition:

The First two numbers in Fibonacci series are 0 and 1  and each subsequent number is sum of the previous two numbers.






Source Code:

import java.util.Scanner;
class FibDemo
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a=1,b=1,c=0,n;
System.out.println("Enter n value");
n=sc.nextInt();
System.out.print(a);
System.out.print(" "+b);
for(i=0;i<n-2;i++)
{
c=a+b;
a=b;
b=c;
System.out.print(" "+c);
}
System.out.println();
System.out.println(" the series is"+c);
}
}

Output:



Also check This Post: Java Program to check whether the String is Palindrome or not





No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...