Java Programs Set 2
Java Programs Set 2
Program 1
class Maxof2{
int i = Integer.parseInt(args[0]);
int j = Integer.parseInt(args[1]);
if(i > j)
else
}
Program 2
class Minof2{
int i = Integer.parseInt(args[0]);
int j = Integer.parseInt(args[1]);
}
Program 3
/* Write a program that will read a float type value from the keyboard and print the following output.
->Given Number.
*/
class ValueFormat{
}
Program 4
*/
class RandomDemo{
for(int i=1;i<=5;i++){
System.out.println((int)(Math.random()*100));
MAYUR KENI
}
}
Program 5
*/
class SwitchDemo{
switch(marks/10){
case 10:
case 9:
case 8:
System.out.println("Excellent");
break;
case 7:
break;
case 6:
System.out.println("Good");
break;
case 5:
break;
case 4:
System.out.println("Poor");
break;
case 3:
case 2:
case 1:
case 0:
break;
default:
}
}
Program 6
class Sum_Product_ofDigit{
while(temp>0){
temp--;
}
temp = num;
result = 1;
temp--;
}
}
Program 7
class Factorial{
int result = 1;
while(num>0){
num--;
}
}
Program 8
class Reverse{
while(num>0){
remainder = num%10;
num = num/10;
}
}
Program 9
Example :
Input - 8
Output - 1 1 2 3 5 8 13 21
*/
class Fibonacci{
MAYUR KENI
System.out.println("*****Fibonacci Series*****");
for(int i=1;i<=num;i++){
f1 = f2;
f2 = f3;
f3 = f1 + f2;
}
}
Program 10
/* Write a program to find sum of all integers greater than 100 and
class SumOfDigit{
int result=0;
for(int i=100;i<=200;i++){
if(i%7==0)
result+=i;
}
}
MAYUR KENI
Program 11
Example:
Input - 5
Output - 1 2 3 4 5 */
class Join{
for(int i=1;i<=num;i++){
}
System.out.println(result);
}
Program 12
class MultiplicationTable{
System.out.println("*****MULTIPLICATION TABLE*****");
for(int i=1;i<=num;i++){
for(int j=1;j<=num;j++){
}
System.out.print("\n");
}
}
Program 13
class Swap{
System.out.println("\n***Before Swapping***");
System.out.println("Number 1 : "+num1);
System.out.println("Number 2 : "+num2);
//Swap logic
System.out.println("\n***After Swapping***");
System.out.println("Number 1 : "+num1);
System.out.println("Number 2 : "+num2);
}
Program 14
/* Write a program to convert given no. of days into months and days.
Example :
Input - 69
class DayMonthDemo{
}
Program 15
eg:
1
2 2
3 3 3
class Triangle{
for(int i=1;i<=num;i++){
for(int j=1;j<=i;j++){
}
System.out.print("\n");
}
}
Program 16
Example:
Input - 5
Output :
5 5 5 5 5
MAYUR KENI
4 4 4 4
3 3 3
2 2
1
*/
class InvertTriangle{
for(int j=1;j<=num;j++){
}
System.out.print("\n");
num--;
}
}
Program 17
Example :
Input - 153
class Armstrong{
int check=0,remainder;
}
if(check == n)
else
}
Program 18
class PrimeNo{
int flag=0;
MAYUR KENI
for(int i=2;i<num;i++){
if(num%i==0)
{
flag = 1;
break;
}
}
if(flag==0)
}
Program 19
Example :
class Palindrome{
int reverse=0,remainder;
MAYUR KENI
}
if(reverse == n)
else
}
Program 20
Example :
Input - 124
class SwitchCaseDemo{
try{
int reverse=0,remainder;
}
switch(remainder){
case 0 :
break;
case 1 :
break;
case 2 :
break;
case 3 :
break;
MAYUR KENI
case 4 :
break;
case 5 :
break;
case 6 :
break;
case 7 :
break;
case 8 :
break;
case 9 :
break;
default:
result="";
}
}
System.out.println(result);
MAYUR KENI
}catch(Exception e){
}
}
Program 21
Example :
Input - 5
class HarmonicSeries{
num--;
}
}
}
MAYUR KENI
Program 22
/*Write a program to find average of consecutive N Odd no. and Even no. */
class EvenOdd_Avg{
int n = Integer.parseInt(args[0]);
int cntEven=0,cntOdd=0,sumEven=0,sumOdd=0;
if(n%2==0){
cntEven++;
sumEven = sumEven + n;
}
else{
cntOdd++;
sumOdd = sumOdd + n;
}
n--;
}
int evenAvg,oddAvg;
evenAvg = sumEven/cntEven;
oddAvg = sumOdd/cntOdd;
MAYUR KENI
}
Program 23
1
2 3
4 5 6
7 8 9 10 ... N */
class Output1{
int c=0;
int n = Integer.parseInt(args[0]);
if(c!=n){
c++;
}
else
}
System.out.print("\n");
MAYUR KENI
}
}
Program 24
0
1 0
1 0 1
0 1 0 1 */
class Output2{
for(int i=1;i<=4;i++){
for(int j=1;j<=i;j++){
}
System.out.print("\n");
}
}
}
Program 25
1
2 4
3 6 9
class Output3{
int n = Integer.parseInt(args[0]);
}
System.out.print("\n");
}
}