Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 57

class prog1

{
//First overloaded function
void check(String str,char ch)
{
int l=str.length();
int count=0;
for(int i=0;i<l;i++)
{
char ch1=str.charAt(i);
if(ch1==ch)
count++;//count the frequency of given character
}
System.out.println("Number of"+ch+"present="+count);
}//end of first method
//Second method begins
void check(String s1)
{
s1=s1.toLowerCase();
int l=s1.length();
for(int i=0;i<l;i++)
{
char ch1=s1.charAt(i);
if(ch1=='a' || ch1=='e' || ch1=='i' || ch1=='o' || ch1=='u')
System.out.print(ch1+" ");//Display the vowels
}
}
}
ALGORITHM
Step 1: Start
1.1 : Accept a string and a character.
1.2 : Find length.
1.3 :Set count as 0.
1.4 Repeat for i=0,1,2…l
Extract the characters of the string.
If character(ch1==ch)
Increase counter variable by 1.
End for.

1.5: Display frequency.


Step 2: start method
2.1: Accept a string.
2.2: Find length.
2.3: Repeat for i=0,1,2…l
Extract the characters of the string.
If character(ch1==’a’ || ch1==’e’…)is a vowel
Display character(ch1).

Step 3: Stop.

VDT

VARIABLE DATA TYPE PURPOSE


str String Accept a string from the
user.
ch char Accept a character from the
user.
L int Find the length of the string.
count int Count and store the
frequency of given
character.
I int Loop variable to control the
loop.
Ch1 char Store each character of the
string
S1 String Accept a string from the
user.
import java.util.*;
class prog2//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of students:");
int N=sc.nextInt();
String name[]=new String[N];//Initialization of name array
int totalmarks[]=new int[N];//Initialization of totalmarks array
int tot=0;
//Input name and totalmarks
for(int i=0;i<N;i++)
{
sc.nextLine();
System.out.println("Enter name of the students:");
name[i]=sc.nextLine();
System.out.println("Enter total marks:");
totalmarks[i]=sc.nextInt();
tot+=totalmarks[i];
}
double avg=tot/(double)N;//Calculate average marks
System.out.println("Average="+avg);//Display Average marks
for(int i=0;i<N;i++)
{
System.out.println("Deviation:"+(totalmarks[i]-avg));//Display deviation
}
}//end of main()
}//end of class
VDT

VARIABLE DATA TYPE PURPOSE


N int Accept number of student.
name[] String Subscripted variable to store
name of the students.
totalmarks[] int Subscripted variable to store
totalmarks of each students.
tot int Store total of the total marks
of the students.
avg double Store average marks.
i int Loop variable to control the
loop.
import java.util.*;
class prog3//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int num[]=new int[15];//Initialization of num array

//Input 15 numbers in an array


System.out.println("Enter numbers:");
for(int i=0;i<15;i++)
{
num[i]=sc.nextInt();
}
//Sorting in ascending order
for(int i=0;i<14;i++)
{
for(int j=0;j<(14-i);j++)
{
if(num[j]>num[j+1])
{
int t=num[j];
num[j]=num[j+1];
num[j+1]=t;
}
}
}
//Display sorted array
System.out.println("sorted array:");
for(int i=0;i<15;i++)
{
System.out.println(num[i]);
}
}
}
VDT

VARIABLE DATA TYPE PURPOSE


num[] int Subscripted variable to store
15 numbers.
i int Loop variable to control the
loop.
t int Third variable used to
interchange two numbers.
import java.util.*;
class prog4//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int num[]=new int[20];//Initialization of num array

//Input 20 numbers in an array


System.out.println("Enter numbers:");
for(int i=0;i<20;i++)
{
num[i]=sc.nextInt();

}
int max=num[0],min=num[0];int sum=0;
//Find largest and smallest number and sumof the elements
for(int i=0;i<20;i++)
{
if(num[i]>max)
max=num[i];
if(num[i]<min)
min=num[i];
sum+=num[i];
}
//Display largest,smallest number and sum of the elements
System.out.println("Largest number="+max);
System.out.println("Smallest number="+min);
System.out.println("Sum of the number="+sum);
}
}
VDT

VARIABLE DATA TYPE PURPOSE


num[] int Subscripted variable to store
20 numbers.
i int Loop variable to control the
loop.
max int Store largest element.
min int Store smallest element.
sum int Store sum of the element.

import java.util.*;
class prog5//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String words[]=new String[20];//Initialization of the array
int max;
//Input 20 words in an array
System.out.println("Enter words:");
for(int i=0;i<20;i++)
{
words[i]=sc.next();

}
//Sorting in descending order
for(int i=0;i<19;i++)
{
max=i;
for(int j=i+1;j<20;j++)
{
if(words[j].compareTo(words[max])>0)
max=j;
}
String t=words[i];
words[i]=words[max];
words[max]=t;
}
System.out.println("Words arranged in descending order are:");
for(int i=0;i<19;i++)
{
System.out.println(words[i]);
}
}
}
VDT

VARIABLE DATA TYPE PURPOSE


words[] String Store 20 words.
I,j int Loop variable control the
loops.
max int Store index of largest
element .
t String Interchange two words.
import java.util.Scanner;

class prog6

{
public static void main(String args[]) {

String wonders[] = {"CHICHEN ITZA", "CHRIST THE REDEEMER", "TAJMAHAL",


"GREAT WALL OF CHINA", "MACHU PICCHU", "PETRA", "COLOSSEUM"};

String locations[] = {"MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU", "JORDAN",


"ITALY"};

Scanner in = new Scanner(System.in);


System.out.print("Enter country: ");
String c = in.nextLine();
int i;

for (i = 0; i < locations.length; i++) {


if (locations[i].equals(c)) {
System.out.println(locations[i] + " - " + wonders[i]);
break;
}
}
if (i == locations.length)
System.out.println("Sorry Not Found!");
}
}

import java.util.*;
class prog7//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter no of students:");
int n=sc.nextInt();
String name[]=new String[n];//Initialization of name array
int roll[]=new int[n];//Initialization of totalmarks array
int sub1[]=new int[n];
int sub2[]=new int[n];
int sub3[]=new int[n];
int avg=0;
//Input name,rollno and three subject marks
for(int i=0;i<n;i++)
{
sc.nextLine();
System.out.println("Enter name of the students:");
name[i]=sc.nextLine();
System.out.println("Enter Roll no:");
roll[i]=sc.nextInt();
System.out.println("Enter three subject marks:");
sub1[i]=sc.nextInt();
sub2[i]=sc.nextInt();
sub3[i]=sc.nextInt();
avg=(sub1[i]+sub2[i]+sub3[i])/3;//Calculation of average marks
System.out.println("Average="+avg);//Display Average marks
//Remarks on average marks
if(avg>=85 && avg<=100)
System.out.println("EXCELLENT");
if(avg>=75 && avg<=84)
System.out.println("DISTINCTION");
if(avg>=60 && avg<=74)
System.out.println("FIRST CLASS");
if(avg>=40 && avg<=59)
System.out.println("PASS");
if(avg<40)
System.out.println("POOR");
}
}
}
VDT

VARIABLE DATA TYPE PURPOSE


n int Store number of students.
name[] String Subscripted variable to store
name of the students.
Roll[] int Subscripted variable to store
roll number of the students.
Sub1[],sub2[],sub3[] int Subscripted variable to store
3 subject marks of the
students.
avg int Store average marks of the
students.

class prog8
{
void joystring(String s,char ch1,char ch2)
{
String s1=s.replace(ch1,ch2);
System.out.println(s1);
}
void joystring(String s)
{
int first_index=s.indexOf(' ');
int last_index=s.lastIndexOf(' ');
System.out.println("First index="+first_index);
System.out.println("Last index="+last_index);
}
void joystring(String s1,String s2)
{
s1=s1+" ";
String s3=s1.concat(s2);
System.out.println("Combined string="+s3);
}
}
VDT

VARIABLE DATA TYPE PURPOSE


S,s1,s2 String Accept a string from the
user.
ch1,ch2 char Accept a two characters
from the user.
s1 String Store the string after replace.
first_index int Store index of first space.

last_index int Store index of last space.


S3 String Store the combined string.

import java.util.*;
class prog9//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String name[]=new String[20];//Initialization of the array
//Input 20 names in an array
System.out.println("Enter names:");
+
for(int i=0;i<20;i++)
{
name[i]=sc.next();

}
//Sorting in descending order
for(int i=0;i<19;i++)
{
for(int j=0;j<(19-i);j++)
{
if(name[j].compareTo(name[j+1])<0)
{
String t=name[j];
name[j]=name[j+1];
name[j+1]=t;
}
}
}
//Display sorted array
System.out.println("sorted array:");
for(int i=0;i<20;i++)
{
System.out.println(name[i]);
}
}
}

VDT

VARIABLE DATA TYPE PURPOSE


name[] String Subscripted variable to store
20 name of the students.
I,j int Loop variable control the
loops.
t String Interchange two strings.
import java.util.Scanner;

class prog10
{
public void checkNumber() {

Scanner in = new Scanner(System.in);

System.out.print("Enter a 2 digit number: ");


int orgNum = in.nextInt();

int num = orgNum;


int count = 0, digitSum = 0, digitProduct = 1;

while (num != 0) {
int digit = num % 10;
num /= 10;
digitSum += digit;
digitProduct *= digit;
count++;
}

if (count != 2)
System.out.println("Invalid input, please enter a 2-digit number");
else if ((digitSum + digitProduct) == orgNum)
System.out.println("Special 2-digit number");
else
System.out.println("Not a special 2-digit number");

}
}
import java.util.Scanner;

class prog11
{
double area(double a, double b, double c) {
double s = (a + b + c) / 2;
double x = s * (s-a) * (s-b) * (s-c);
double result = Math.sqrt(x);
return result;
}

double area (int a, int b, int height) {


double result = (1.0 / 2.0) * height * (a + b);
return result;
}

double area (double diagonal1, double diagonal2) {


double result = 1.0 / 2.0 * diagonal1 * diagonal2;
return result;
}
}
import java.util.Scanner;

class prog12
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Type 1 for Term Deposit");
System.out.println("Type 2 for Recurring Deposit");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
double p = 0.0, r = 0.0, a = 0.0;
int n = 0;

switch (ch) {
case 1:
System.out.print("Enter Principal: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in years: ");
n = in.nextInt();
a = p * Math.pow(1 + r / 100, n);
System.out.println("Maturity amount = " + a);
break;

case 2:
System.out.print("Enter Monthly Installment: ");
p = in.nextDouble();
System.out.print("Enter Interest Rate: ");
r = in.nextDouble();
System.out.print("Enter time in months: ");
n = in.nextInt();
a = p * n + p * ((n * (n + 1)) / 2) * (r / 100) * (1 / 12.0);
System.out.println("Maturity amount = " + a);
break;

default:
System.out.println("Invalid choice");
}
}
}
class prog13//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int y[]={1982,1987,1993,1996,1999,2003,2006,2007,2009,2010};//Initialization of the
array
int lb=0,ub=9,mid,yr;boolean flag=false;
System.out.println("Enter the year to be searched:");
yr=sc.nextInt();
//Binary search
while(lb<=ub)
{
mid=(lb+ub)/2;
if(y[mid]<yr)
lb=mid+1;
if(y[mid]>yr)
ub=mid-1;
if(y[mid]==yr)
{
flag=true;
break;
}
}//end of while loop
if(flag==true)
System.out.println("Record exists");
else
System.out.println("Record does not exists");
}
}

VDT

VARIABLE DATA TYPE PURPOSE


y[] int Store years.
lb int Store index of lowest cell.
ub int Store index of highest cell.
mid int Store index of middle cell.
flag boolean Indicates whether search is
successful or not.

Prog14
import java.util.Scanner;

class FruitJuice
{
private int product_code;
private String flavour;
private String pack_type;
private int pack_size;
private int product_price;

public FruitJuice() {
product_code = 0;
flavour = "";
pack_type = "";
pack_size = 0;
product_price = 0;
}

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter Flavour: ");
flavour = in.nextLine();
System.out.print("Enter Pack Type: ");
pack_type = in.nextLine();
System.out.print("Enter Product Code: ");
product_code = in.nextInt();
System.out.print("Enter Pack Size: ");
pack_size = in.nextInt();
System.out.print("Enter Product Price: ");
product_price = in.nextInt();
}
public void discount() {
product_price -= 10;
}

public void display() {


System.out.println("Product Code: " + product_code);
System.out.println("Flavour: " + flavour);
System.out.println("Pack Type: " + pack_type);
System.out.println("Pack Size: " + pack_size);
System.out.println("Product Price: " + product_price);
}

public static void main(String args[]) {


FruitJuice obj = new FruitJuice();
obj.input();
obj.discount();
obj.display();
}
}
import java.util.Scanner;

class prog15
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the ISBN: ");
long isbn = in.nextLong();

int sum = 0, count = 0, m = 10;


while (isbn != 0) {
int d = (int)(isbn % 10);
count++;
sum += d * m;
m--;
isbn /= 10;
}
if (count != 10) {
System.out.println("Illegal ISBN");
}
else if (sum % 11 == 0) {
System.out.println("Legal ISBN");
}
else {
System.out.println("Illegal ISBN");
}
}
}

public class prog16


{
public static void main(String args[]) {
for (int i = 1000; i <= 9999; i++) {
int secondHalf = i % 100;
int firstHalf = i / 100;
int sum = firstHalf + secondHalf;
if (i == sum * sum)
System.out.println(i);
}
}
}
import java.util.*;
class prog17//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int num[]=new int[10];//Initialization of num array

//Input 10 numbers in an array


System.out.println("Enter numbers:");
for(int i=0;i<10;i++)
{
num[i]=sc.nextInt();

}
//Bubble Sorting in descendin order
for(int i=0;i<9;i++)
{
for(int j=0;j<(9-i);j++)
{
if(num[j]<num[j+1])
{
int t=num[j];
num[j]=num[j+1];
num[j+1]=t;
}
}
}
//Display sorted array
System.out.println("sorted array:");
for(int i=0;i<10;i++)
{
System.out.println(num[i]);
}
}
}
VDT

VARIABLE DATA TYPE PURPOSE


num[] int Subscripted variable to store
15 numbers.
i int Loop variable to control the
loop.
t int Third variable used to
interchange two numbers.
class prog18
{
double series(double n) {
double sum = 0;
for (int i = 1; i <= n; i++) {
double term = 1.0 / i;
sum += term;
}
return sum;
}

double series(double a, double n) {


double sum = 0;
int x = 1;
for (int i = 1; i <= n; i++) {
int e = x + 1;
double term = x / Math.pow(a, e);
sum += term;
x += 3;
}
return sum;
}

public static void main(String args[]) {


prog18 obj = new prog18();
System.out.println("First series sum = " + obj.series(5));
System.out.println("Second series sum = " + obj.series(3, 8));
}
}

import java.util.*;
class prog19//class begins
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int num[]=new int[15];//Initialization of num array

//Input 10 numbers in an array


System.out.println("Enter numbers:");
for(int i=0;i<10;i++)
{
num[i]=sc.nextInt();

}
//Interchange the consecutive number
for(int i=0;i<10;i+=2)
{
int t=num[i];
num[i]=num[i+1];
num[i+1]=t;
}
//Final Array
System.out.println("Final Array");
for(int i=0;i<10;i++)
{
System.out.print(num[i]+",");

}
}
}
VDT

VARIABLE DATA TYPE PURPOSE


num[] int Subscripted variable to store
15 numbers.
i int Loop variable to control the
loop.
t int Third variable used to
interchange two numbers.

class prog20
{
public void polygon(int n, char ch) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
System.out.print(ch);
}
System.out.println();
}
}

public void polygon(int x, int y) {


for (int i = 1; i <= x; i++) {
for (int j = 1; j <= y; j++) {
System.out.print('@');
}
System.out.println();
}
}

public void polygon() {


for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= i; j++) {
System.out.print('*');
}
System.out.println();
}
}

public static void main(String args[]) {


prog20 obj = new prog20();
obj.polygon(2, 'o');
System.out.println();
obj.polygon(2, 5);
System.out.println();
obj.polygon();
}
}
Prog21
import java.util.Scanner;

public class Mobike


{
private int bno;
private int phno;
private int days;
private int charge;
private String name;

public void input() {


Scanner in = new Scanner(System.in);
System.out.print("Enter Customer Name: ");
name = in.nextLine();
System.out.print("Enter Customer Phone Number: ");
phno = in.nextInt();
System.out.print("Enter Bike Number: ");
bno = in.nextInt();
System.out.print("Enter Number of Days: ");
days = in.nextInt();
}

public void compute() {


if (days <= 5)
charge = days * 500;
else if (days <= 10)
charge = (5 * 500) + ((days - 5) * 400);
else
charge = (5 * 500) + (5 * 400) + ((days - 10) * 200);
}

public void display() {


System.out.println("Bike No.\tPhone No.\tName\tNo. of days \tCharge");
System.out.println(bno + "\t" + phno + "\t" + name + "\t" + days
+ "\t" + charge);
}

public static void main(String args[]) {


Mobike obj = new Mobike();
obj.input();
obj.compute();
obj.display();
}
}
public class Program22
{
public static void main(String args[]) {
final int SIZE = 10;
Scanner in = new Scanner(System.in);
String cities[] = new String[SIZE];
String stdCodes[] = new String[SIZE];
System.out.println("Enter " + SIZE +
" cities and their STD codes:");

for (int i = 0; i < SIZE; i++) {


System.out.print("Enter City Name: ");
cities[i] = in.nextLine();
System.out.print("Enter its STD Code: ");
stdCodes[i] = in.nextLine();
}

System.out.print("Enter name of city to search: ");


String city = in.nextLine();

int idx;
for (idx = 0; idx < SIZE; idx++) {
if (city.compareToIgnoreCase(cities[idx]) == 0) {
break;
}
}

if (idx < SIZE) {


System.out.println("Search Successful");
System.out.println("City: " + cities[idx]);
System.out.println("STD Code: " + stdCodes[idx]);
}
else {
System.out.println("Search Unsuccessful");
}
}
}
import java.util.Scanner;

public class Prog23


{
public static int fact(int y) {
int f = 1;
for (int i = 1; i <= y; i++) {
f *= i;
}
return f;
}

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int num = in.nextInt();

int t = num;
int sum = 0;
while (t != 0) {
int d = t % 10;
sum += fact(d);
t /= 10;
}

if (sum == num)
System.out.println(num + " is a special number");
else
System.out.println(num + " is not a special number");

}
}
public class Prog24
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word: ");
String str = in.nextLine();
str = str.toLowerCase();
String newStr = "";
int len = str.length();

for (int i = 0; i < len; i++) {


char ch = str.charAt(i);

if (str.charAt(i) == 'a' ||
str.charAt(i) == 'e' ||
str.charAt(i) == 'i' ||
str.charAt(i) == 'o' ||
str.charAt(i) == 'u') {

char nextChar = (char)(ch + 1);


newStr = newStr + nextChar;

}
else {
newStr = newStr + ch;
}
}

System.out.println(newStr);
}
}

import java.util.Scanner;

public class Prog25


{
public void compare(int a, int b) {

if (a > b) {
System.out.println(a);
}
else {
System.out.println(b);
}

public void compare(char a, char b) {


int x = (int)a;
int y = (int)b;

if (x > y) {
System.out.println(a);
}
else {
System.out.println(b);
}

public void compare(String a, String b) {

int l1 = a.length();
int l2 = b.length();

if (l1 > l2) {


System.out.println(a);
}
else {
System.out.println(b);
}

public static void main(String args[]) {


Scanner in = new Scanner(System.in);
Prog25 obj = new Prog25();

System.out.print("Enter first integer: ");


int n1 = in.nextInt();
System.out.print("Enter second integer: ");
int n2 = in.nextInt();
obj.compare(n1, n2);

System.out.print("Enter first character: ");


char c1 = in.next().charAt(0);
System.out.print("Enter second character: ");
char c2 = in.next().charAt(0);
in.nextLine();
obj.compare(c1, c2);

System.out.print("Enter first string: ");


String s1 = in.nextLine();
System.out.print("Enter second string: ");
String s2 = in.nextLine();
obj.compare(s1, s2);
}
}
import java.util.*;
class Project26
{
int bubbleSort(int b[]){
int l = b.length;
for(int i=0;i<l-1;i++){
for(int j=0; j<i-l-1; j++){
if(b[j]>b[j+1])
{
int temp = b[j];
b[j] = b[j+1];
b[j+1] = temp;
}
}
}
if(l==5)
{
return b[2];
}
else
{
return b[l-2];
}

public static void main(String args[])


{
int arr1[],arr2[];
arr1=new int[5];
arr2=new int[7];

System.out.println("Enter the elements of the first array");


Scanner sc=new Scanner(System.in);
for(int i=0;i<5;i++)
{
arr1[i]=sc.nextInt();
}

System.out.println("Enter the elements of the Second array");


for(int i=0;i<7;i++)
{
arr2[i]=sc.nextInt();
}
Project26 obj = new Project26();
System.out.println("second Smallest = "+obj.bubbleSort(arr1) + " Second Largest "+
obj.bubbleSort(arr2));
}
}

import java.util.Scanner;

public class Project27


{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter size of array: ");
int n = in.nextInt();

int arr[] = new int[n];


System.out.println("Enter array elements:");
for (int i = 0; i < n; i++) {
arr[i] = in.nextInt();
}

for (int i = 0; i < n - 1; i++) {


for (int j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}

System.out.println("Number\tFrequency");
int count = 0;
for (int i = 0; i < n - 1; i++) {
count++;
if (arr[i] != arr[i + 1]) {
System.out.println(arr[i] + "\t" + count);
count = 0;
}
}

//Print frequency of last element


count++;
System.out.println(arr[n - 1] + "\t" + count);
}
}

import java.util.*;
class Project28
{
boolean prime(int n)
{
for(int i=2;i<n;i++)
{
if (n%i==0)return false;
}
return true;
}
public static void main(String args[])
{
int i;
Scanner sc=new Scanner(System.in);
i=sc.nextInt(); //79
Project28 abc = new Project28();
if(abc.prime(i)==false){
System.out.println("Enter Prime Number only");
return ;
}

else{
int temp=0;
while(i!=0){
int b;
b=i%10;
temp=temp*10+b;
i=i/10;
}
if(abc.prime(temp)==true)
System.out.println(temp+" Is a Prime Number");
else
System.out.println(temp+" Is not a Prime Number");

}
}
import java.util.*;
class Project29
{
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
String abc=sc.next();
abc=abc.toUpperCase();
int l = abc.length();

if (abc.charAt(0)==abc.charAt(l-1))
{
boolean flag=true;
for(int i=1;i<l/2;i++)
{
if(abc.charAt(i)!=abc.charAt(l-1-i)){
flag=false;
break;
}
}
if(flag)
System.out.println("Palindrome Word");
else if(!flag)
System.out.println("Special Word");

}else
System.out.println("Neither Special nor Palindrome");
}
}

import java.util.*;
class Project30
{
public static void main (String args[])
{
int input;
Scanner sc = new Scanner(System.in);
input=sc.nextInt();
switch(input){
case 1: int i;
int j;
for(i=7;i>=1;i--)
{
for(j=i;j>=1;j--)
System.out.print(j+" ");
System.out.println();
}
break;
case 2:
int a,b;
for(a=1;a<=9;a++)
{
int d=8;
System.out.print(a+" ");
int temp=a;
for(b=1;b<a;b++){
temp+=d;
System.out.print(temp+" ");
d--;
}
System.out.println();
}

break;

case 3:
for(int x=1; x<=9;x++)
{
int alpha = 65;
for(int y=0; y<x; y++)
{
System.out.print((char)(alpha+y)+" ");
}
System.out.println();
}
break;
default:
}
}
}

You might also like