
I)WAP to print following series: 1) 1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 2) (5!/x)+(10!/xx)+(15!/xx*x)+.....n terms.
II)Write a menudriven program to perform the following as long as user wants: a) Convert decimal number to binary number. b) Convert binary number to decimal number.

import java.io.*;
class Pyramid{
public static void main(String args[]){
int x,y;
int rows = 4;
for (y = 1; y <= rows; ++y) {
for (x = y; x < rows; ++x) {
System.out.print(" ");
}
for (x = 0; x < y; ++x) {
System.out.print((y+x) % 10);
}
for (x = y - 1; x > 0; --x) {
System.out.print((y+x-1) % 10);
}
System.out.println();
}
}
}

import java.util.*;
class MenuDrivenExample
{
public static void main(String[] args)
{
boolean exit=false;
Scanner input=new Scanner(System.in);
System.out.println("1 Convert Decimal to Binary");
System.out.println("2 Convert Binary to Decimal");
System.out.println("3 Exit");
do{
System.out.print("Enter your choice: ");
int choice=input.nextInt();
switch(choice){
case 1:
System.out.print("Enter Decimal Number: ");
int i = input.nextInt();
String bi = Integer.toBinaryString(i);
System.out.println("Binary of "+i+" is: "+bi);
break;
case 2:
System.out.print("Enter Binary Number: ");
String str = input.next();
int binary= Integer.parseInt(str,2);
System.out.println("Decimal of "+str+" is: "+binary);
break;
case 3:
exit=true;
System.exit(0);
break;
}
}
while(!exit);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.