You are on page 1of 18

Switch Case

import java.util.*;

class SwitchCase

public static void main(String[]args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter your Choice:");

System.out.println("Enter 1 to print Alphabet Pattern:");

System.out.println("Enter 2 to print Number pattern:");

System.out.println("Enter 3 to find sum of the given series:");

int ch=sc.nextInt();

int i,j,c=0;

int k=0;

char chr=' ';

chr='a';

switch (ch)

case 1: System.out.println("Enter the number of rows:");

int n=sc.nextInt();

for (i=1;i<=n;i++)

System.out.print(chr++);

--chr;

for(i=1;i<n;i++)

System.out.print(--chr);

System.out.println();

for(i=n-1;i>=1;i--)

chr='a';

for (j=1;j<=i;j++)

System.out.print(chr++);

for(k=1;k<=c;k++)
System.out.print(" ");

for (j=1;j<=i;j++)

System.out.print(--chr);

System.out.println();

c=c+2;

c=c-4;

for (i=2;i<n;i++)

chr='a';

for (j=1;j<=i;j++)

System.out.print(chr++);

for (k=1;k<=c;k++)

System.out.print(" ");

for (j=1;j<=i;j++)

System.out.print(--chr);

System.out.println();

c=c-2;

chr='a';

for (i=1;i<=n;i++)

System.out.print(chr++);

--chr;

for (i=1;i<n;i++)

System.out.print(--chr);

break;

case 2: System.out.println("Enter the Number of terms:");

int num=sc.nextInt();

c=num-1;

for (i=1;i<=num;i++)

for (k=1;k<=c;k++)

System.out.print(" ");

for (j=1;j<=i;j++)
System.out.print(j);

for (j=i-1;j>=1;j--)

System.out.print(j);

System.out.println();

c=c-1;

c=c+2;

for (i=num-1;i>=1;i--)

for (k=1;k<=c;k++)

System.out.print(" ");

for (j=1;j<=i;j++)

System.out.print(j);

for (j=i-1;j>=1;j--)

System.out.print(j);

System.out.println();

c=c+1;

break;

case 3: System.out.println("Enter the last term in the Series");

n=sc.nextInt();

c=5;

int sum=0;

int term=0;

for (i=5;i<n;i=i+5)

if (i%2==0)

term=(c*5)-1;

sum=sum-term;

else

term=(c*5)+1;
sum=sum+term;

c=c+5;

System.out.println("Sum of the Series:"+sum);

break;

default: System.out.println("Wrong Input...Please Try Again");

Function: Conversion of Money


import java.util.*;

class ConversionName

void Sort(String Country[],String Currency[],double exchange[])

int i,j;

double temp=0.0;

String t=" ";

String tem=" ";

for ( i=0;i<10;i++)

for (j=0;j<9-i;j++)

if (exchange[j]>exchange[j+1])

temp=exchange[j];

t=Country[j];

tem=Currency[j];

exchange[j]=exchange[j+1];

Country[j]=Country[j+1];

Currency[j]=Currency[j+1];
exchange[j]=temp;

Country[j]=t;

Currency[j]=tem;

public double Rate(String C,double exchange[],String Country[])

double ex=0.0;

int k=0;

for (int i=0;i<10;i++)

if (C.equalsIgnoreCase(Country[i])==true)

ex=exchange[i];

k=1;

if (k!=1)

return(0.0);

else

return(ex);

public double Convert(double ex,double amt)

double inr=0.0;

inr=(ex*amt);

return (inr);

public double Commission(double inr)

{
double com=0.0;

double amt=0.0;

double sum=0.0;

if (inr<=50000)

com=0.05;

else if (inr>50000&&inr<250000)

com=0.07;

else if (inr>=250000&&inr<5000000)

com=0.08;

else

com=0.09;

amt=inr*com;

sum=inr-amt;

return(sum);

public static void main(String[]args)

Scanner sc=new Scanner(System.in);

double exchange[]=new double[5];

String Country[]=new String[5];

String Currency[]=new String[5];

System.out.println("Enter the Country Name,Currency Name and Exchange Rate");

for (int i=0;i<10;i++)

System.out.println("Enter country name:");

Country[i]=sc.next();

System.out.println("Enter currency name:");

Currency[i]=sc.next();

System.out.println("Enter the Exchange Rate:");

exchange[i]=sc.nextDouble();

ConversionName ob=new ConversionName();

ob.Sort(Country,Currency,exchange);

System.out.println("Enter the Name of the Country you want to search for:");


String C=sc.next();

System.out.println("Enter the Name of the Currency");

String Cur=sc.next();

System.out.println("Enter the Numerical Amount of Money");

double amt=sc.nextDouble();

double rate=ob.Rate(C,exchange,Country);

double inr=ob.Convert(rate,amt);

double com=ob.Commission(inr);

System.out.println("The Equivalent Amount in INR: "+inr);

System.out.println("Including the Commission Charges: "+com);

Legendary ASCII Shift


import java.util.*;

class ASCII

public static void main (String[]args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter a Sentence:");

String str=sc.nextLine();

str=str+" ";

String wd=" ";

int p=str.length();

System.out.println("Enter a Number");

int num=sc.nextInt();

int copy=num;

char chr=' ';

char ch=' ';

char ch1=' ';

char ch2=' ';

int val=0;

int ascii=0;
int diff=0;

String st=" ";

for (int i=0;i<p;i++)

chr=str.charAt(i);

ascii=(char)chr;

val=ascii+num;

if (val>122&&Character.isLowerCase(chr)==true)

num=num-(122-ascii);

num=num%26;

st=st+(char)(96+num);

else if (val>90&&Character.isUpperCase(chr)==true)

num=num-(90-ascii);

num=num%26;

st=st+(char)(64+num);

else if (ascii==32)

st=st+" ";

else

st=st+(char)(val);

num=copy;

System.out.println("The Encoded String:");

System.out.println(st);

String st1=" ";

st=st+" ";

for (int j=0;j<=p;j++)

chr=st.charAt(j);

if (chr!=' ')
wd=wd+chr;

else

st1=wd+st1;

wd=" ";

System.out.println("The String in reversed format:");

System.out.println(st1);

Number Manipulation
import java.util.*;

class Number

public static void main(String[]args)

Scanner in=new Scanner(System.in);

System.out.println("Enter a Number");

int num=in.nextInt();

int dig,sum=0,avg;

int copy=num;

int count=0;

while (num!=0)

dig=num%10;

sum=sum+dig;

count++;

num=num/10;

avg=(int)(sum/count);

System.out.println(avg);

int s=0;
s=sum+avg;

int dup=sum;

int d,n;

if (s>9)

d=dup%10;

n=sum+d;

System.out.println("The New Number: "+n);

System.exit(0);

System.out.println("The New Number:"+s);

Variable List of Switch Case Program


Variable Name Data Type Use
ch int To Store Choice of the User
i int Outer LCV
j int Inner LCV
chr char Controls the Character to be
Displayed
k int Innermost LCV
n int Takes Input Number of rows in
Alphabet Pattern
c int Regulates The Indentation
num int Regulates Number of rows in
Number Pattern
c (reinitialized) int Maintains the Common
Difference in the Series
n int Takes Input Last Term of the
Series
term int Stores the succeeding term of
the Series
sum int Accumulates the Sum of the
Series

Variable List of Legendary ASCII Shift Program


Variable Name Data Type Function
str String Takes Input the
Sentence
p Int Stores the length of str
num int Takes Input the Shift in
Ascii Values
chr,ch,ch1,ch2 char Used to Store Characters
in Various Places
val int Stores the sum of ascii
value of the character
and num
ascii int Stores the Ascii value of
a character
st String Stores the Encoded
String
copy int Duplicates the shift in
ascii value by the User
i int LCV in Loop to Encode
String
j int LCV in Loop to reverse
the Encoded String
st1 String Stores the word-wise
Reversed string.

Parameter List of Function/Method Based Program


Variable Name Data Type Function
Country[] String Array To Store 10 Country
Names
Currency[] String Array To Store 10 Currency
Names
exchange[] Double Array To Store the Equivalent
amount in INR
i int Outer LCV in Bubble Sort
j int Inner LCV in Bubble Sort
temp double Temporary Variable for
exchange[]
tem String Temporary Variable for
Currency[]
t String Temporary Variable for
Country[]
C String Country to be Searched
ex double Store the exchange rate
of the searched Currency
k int Flag Variable in Linear
Search
inr double Equivalent Amount in
Indian Rupees, excluding
Commission
com double Commission Percentage
amt Double Amount the User has
asked to be Converted
into INR
sum double Equivalent Amount in
Indian Rupees, including
Commission
Ob() Object An Instance of
Conversion
Cur String Takes Input the Name of
the Currency to be
Searched
Void Convert() Member Methods To convert the money in
INR
Void Commission() Member Methods To Subsidise the amount
of Commission to be
Paid
Void Sort() Member Methods To Bubble Sort the three
arrays in ascending
order
Public double rate() Member Method Returns the Exchange
Rate of The Country
Searched For

Parameter List of Number Average of Digits Program


Variable List Data Type Function
num int To Take Input the
Number Given by the
User
dig int To extract indivivual
digits
sum int To Store the sum of the
Digits
avg int To Store the Average of
the Digits
copy int Duplicates the number
given by the user
count int To Store the Number of
Digits in the number
s int Stores the sum of sum of
the digits and average of
the number
dup int Duplicates the sum of
the digits of the given
number
n int New number formed if
the total is greater than
9
d int Extracts the digits of s
from the right
Switch Case Program Output (Program-1)
ASCII Code Shift Output (Program-2)
Number Manipulation Program Output (Program-3)

===========================================================================
Function: Conversion of Money Output (Program-4):

---------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------

You might also like