Category Archives: java

Java Programming: Experiment 1 (codes)

click to download SE IT/ Sem 3/ Rev 2016/ Java Programming/ Experiment 1 (codes) (rar file)

i) Write a Java program to understand how to accept input using Scanner or BufferedReader and print output using System.out.println statement. (ScannerTest.java, BufferedReaderTest.java)
ii) Write a Java program to display the default value of all primitive data types
in Java. (DefValues.java)
iii) Write a Java program that prints all real solutions to the quadratic equation
ax2+bx+c = 0. Read in a, b, c and use the quadratic formula. If the discriminate b2-
4ac is negative, display a message stating that there are no real solutions. (QuadEq.java)
iv) Write a java program to test whether string is palindrome or not (Palindrome.java)
v) Write a java program to count number of alphabets, digits, special symbols,
blank spaces and words from the given sentence. (SentenceContent.java)
vi) Write a java program to count number of vowels and consonants from the given
strings. (VowelsConsonants.java)
vii) Write a Menu driven program in java to implement simple banking application. Application should read the customer name, account number, initial balance, rate of interest, contact number and address field etc. Application should have following
methods.
1. createAccount()
2. deposit()
3. withdraw()
4. computeInterest()
5. displayBalance() (Account.java)
viii) Write a menu driven Java program which will read a number and should implement the following methods
1. factorial()
2. reverse()
3. testArmstrong()
4. testPalindrome()
5. testPrime()
6. fibonacciSeries() (NumericOps.java)
ix) Write a Java program to demonstrate Method overloading. (MethodOverloading.java)

Advertisements

OOPM: java program for fibonacci series

//fibonacci w/o recursion
import java.io.*;

class Fibbo{
public static void main(String args[])
{
int n,x,y,temp;
n = Integer.parseInt(args[0]);
x=0;
y=1;
do{
System.out.print(x + ” “);
temp = x;
x = y;
y = temp + y;
n–;
}while(n>0);
}
}

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

//fibonacci with recursion
import java.io.*;

class Fibbo
{
void fib(int x, int y, int n)
{
int temp;
if(n<=0)
System.out.print(x + ” “);
else
{
System.out.print(x + ” “);
temp = x;
x = y;
y+=temp;
fib(x,y,–n);
}
}
}

class FibboRec{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
Fibbo f = new Fibbo();
System.out.print(“Fibonacci series:”);
f.fib(0,1,n);
}
}

OOPM: java program for reverse of number

//reverse of number w/o recursion
import java.io.*;

class Rev{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
while(n!=0)
{
System.out.print(n%10);
n/=10;
}
}
}

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

//reverse of number with recursion
import java.io.*;

class revNum
{
void rev(int n)
{
if(n<10)
System.out.println(n);
else
{
System.out.print(n%10);
rev(n/10);
}
}
}

class RevRec{
public static void main(String args[])
{
int n;
n = Integer.parseInt(args[0]);
revNum r = new revNum();
System.out.print(“Reverse of number:”);
r.rev(n);
}
}