0% found this document useful (0 votes)
3 views21 pages

Java Programs for Time, Luck, and Math

Uploaded by

suhanthy2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views21 pages

Java Programs for Time, Luck, and Math

Uploaded by

suhanthy2007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

1:

class first
declare h, m

void input()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the hour")
initialize h
print("Enter the mins")
initialize m
if(h > 12 || m > 59)
print("Incorrect input")
[Link](0)
end of if
void cal()
Step 1: String s[] = {"Zero", "One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve",
"Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen",
"Nineteen", "Twenty", "Twenty One",
"Twenty Two", "Twenty Three", "Twenty Four", "Twenty Five", "Twenty Six",
"Twenty Seven",
"Twenty Eight", "Twenty Nine"}
if(m == 0)
if(m < 10)
print(h + ":0" + m)
else
print(h + ":" + m)
print(s[h] + " o'clock")

else if(m < 30)


if(m < 10)
print(h + ":0" + m)
else
print(h + ":" + m)
print(s[m] + " mins past " + s[h])

else if(m == 45)


print(h + ":" + m)
print("Quarter to " + s[h + 1])

else if(m == 30)


print(h + ":" + m)
print("Half past " + s[h])

else if(m == 50)


print(h + ":" + m)
print("Quarter past " + s[h])

else if(m > 30)


print(h + ":" + m)
print(s[60 - m] + " mins to " + s[h + 1])

else
print("incorrect")
end of nested if else

public static void main()


Step 0: Start
Step 1: declare object ob
Step 2: call input()
Step 3: call cal()
Step 4: Stop

2:
class lucky
declare s, sum

void input()
Step 1: Scanner sc = new Scanner([Link])
print("Enter")
s = [Link]()

void cal()
Step 1: sum = 0

while(s != 1)
while(s > 0)
int b = s % 10 // 9,1
sum = sum + b // 10
s = s / 10 // 1
s = sum
sum = 0
end of while loop

if(s / 10 == 0)
break

void print()
if(s == 1)
print("Lucky")
else
print("Not lucky")
end of if else

public static void main()


Step 0:Start
Step 1:lucky ob = new lucky()
Step 2:[Link]()
Step 3:[Link]()
Step 4:[Link]()
Step 5: Stop

3:
class third
int d, m, y
String s

void input()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the first day of the year")
s = [Link]()
print("Enter the date of which the day is to be found")
d = [Link]()
print("Enter the month number of which the day is to be found")
m = [Link]()
print("Enter the year")
y = [Link]()

void cal()
Step1: String days[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"}
int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
int d1 = -1
for(int i = 0, [Link], by 1
if(days[i].equalsIgnoreCase(s))
d1 = i
break
end of if
end of for loop
int tdays = 0
for(int i = 0; i < m - 1; i++)
tdays += months[i]
end of for loop
tdays += d
int cday = tdays % 7 + d1 - 1
if(cday > 7)
cday -= 7

if(y % 4 == 0)
print("Day is " + days[cday + 1])
else
print("Day is " + days[cday])
end of if else

public static void main()


Step 0: Start
Step 1: third ob = new third()
Step 2: [Link]()
Step 3: [Link]()
Step 4: Stop

4:
class fourth
void doall()
Step 1:Scanner scan = new Scanner([Link])
print("Enter any number from 2 to 5 (both inclusive")
int n = [Link]()
int count = 0
char ch
for(int i = 1; till n, by 1)
for(int j = 1; j till n by 1)
if(i == j)
continue

for(int k = 1; till n by 1)
if(k == j || k == i)
continue

for(int l = 1;till n by 1)
if(l == i || l == j || l == k)
continue

for(int m = 1; till n by 1)
if(m == i || m == j || m == k || m == l)
continue
print(i + " " + j + " " + k + " " + l + " " + m)
count++
end of inner for loop
if(n == 4)
print(i + " " + j + " " + k + " " + l)
count++
end of if else
if(n == 3)
print(i + " " + j + " " + k)
count++

if(n == 2)
print(i + " " + j)
count++
end of if else
end of inner for loop
print("There were " + count + " possible combinations")
print("")
end of if else
end of outer for loop

public static void main()


Step 0: Start
Step 1: fourth bo = new fourth()
Step 2: [Link]()
Step 3: Stop

5:
class adding
int a, b
String sum

void input()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the first number in binary itself")
a = [Link]()
print("Enter the second number in binary itself")
b = [Link]()

void cal()
Step 1: String b2 = ""
String a1 = [Link](a)
String b1 = [Link](b)

if([Link]() == [Link]())
for(int i = [Link]();till 0 , by 1)
int c = 0
if([Link](i) == '0' && [Link](i) == '0')
sum = "0" + sum
else if([Link](i) == '1' && [Link](i) == '0')
sum = "1" + sum
else if([Link](i) == '0' && [Link](i) == '1')
sum = "1" + sum
else if([Link](i) == '1' && [Link](i) == '1')
sum = "0" + sum
end of for loop
else if([Link]() > [Link]())
int z = [Link]() - [Link]() // difference of zeros
while(z > -1)
b2 = "0" + b1
z--
end of while
print("b2= " + b2)
for(int i = [Link]();till 0, by 1)
int c = 0
if([Link](i) == '0' && [Link](i) == '0')
sum = "0" + sum
else if([Link](i) == '1' && [Link](i) == '0')
sum = "1" + sum
else if([Link](i) == '0' && [Link](i) == '1')
sum = "1" + sum
else if([Link](i) == '1' && [Link](i) == '1')
sum = "0" + sum
end of for loop
else
int z = [Link]() - [Link]() // difference of zeros
while(z > -1)
b2 = "0" + b1
z--
end of if else if
print("b2= " + b2)
for(int i = [Link]();til 0, by 1)
int c = 0
if([Link](i) == '0' && [Link](i) == '0')
sum = "0" + sum
else if([Link](i) == '1' && [Link](i) == '0')
sum = "1" + sum
else if([Link](i) == '0' && [Link](i) == '1')
sum = "1" + sum
else if([Link](i) == '1' && [Link](i) == '1')
sum = "0" + sum
end of for loop
end of if else if

void print()
Step 1:print("Sum= " + sum)

public static void main()


Step 0: Start
Step 1:adding ob = new adding()
Step 2: [Link]()
Step 3: [Link]()
Step 4: [Link]()
Step 5: Stop

6::
class sixth

void doall()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the no.")
int n = [Link]()
if(n < 2 || n > 100)
print("Enter the number within the range")
[Link](0)
end of if
int z = 0
String c = ""
int co = 0
while(n > 0)
z = n % 2
c = z + c
n = n / 2
if(z == 1)
co++
else
continue
end of if else
end of while

print("binary equivalent is= " + c)


if(co % 2 == 0)
print("It is an evil no.")
else
print("It is not an evil no.")
end of if else

public static void main()


Step 0: Start
Step 1: sixth ob = new sixth()
Step 2: [Link]()
Step 3: Stop

7:

class seven

void doit()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the no. of elements")
int n = [Link]()
int a[] = new int[n]
print("Enter the elements")
for(int i = 0; till n, by 1)
a[i] = [Link]()
end of for loop
int t = 0
for(int i = 0; till n-1, by 1)
for(int j = 0; till n-1-i, by 1)
if(a[j + 1] < a[j])
t = a[j]
a[j] = a[j + 1]
a[j + 1] = t
end of if
end of inner for loop
end of outer for loop

for(int i = 0; till n, by 1)
[Link](a[i])
end of for loop
String z = ""
String b = ""
for(int i = 0;till n, by 1)
if(i % 2 == 0)
b = b + [Link](a[i]) // even038
else
z = z + [Link](a[i]) // odd17
end of if else
end of for loop
String c = ""
if(n % 2 != 0)
for(int i = [Link]() - 1;till 0, by 1)
c = c + [Link](i) // 830
end of for loop
print()
print(b + c)
else
for(int i = [Link]() - 1; till 0, by 1)
c = c + [Link](i) // 830
end of for loop
print()
print(z + c)
end of if else

public static void main()


Step 0: Start
Step 1: seven ob = new seven()
Step 2: [Link]()
Step 3: Stop

8:
class mul

void doit()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the no. of rows of 1st matrix")
int r1 = [Link]()
print("Enter the no. of columns of 1st matrix")
int c1 = [Link]()
print("Enter the elements of 1st matrix")
int m1[][] = new int[r1][c1]
for(int i = 0; i till r1, by 1)
for(int j = 0; j till c1, by 1)
m1[i][j] = [Link]()
end of inner for loop
end of outer for loop

print("Enter the no. of rows of 2nd matrix")


int r2 = [Link]()
print("Enter the no. of columns of 2nd matrix")
int c2 = [Link]()
print("Enter the elements of 2nd matrix")
int m2[][] = new int[r2][c2]
for(int i = 0; i till r2, by 1)
for(int j = 0; j till c2, by 1)
m2[i][j] = [Link]()
end of inner for loop
end of outer for loop
int m3[][] = new int[r1][c2]
for(int i = 0; till r1, by 1)
for(int j = 0; till c2, by 1)
m3[i][j] = m1[i][j] * m2[i][j]
end of inner for loop
end of outer for loop
print("After multiplying the matrix is:")
for(int i = 0; till r1, by 1)
for(int j = 0; till c1, by 1)
print(m3[i][j] + " ")
print()
end of inner for loop
end of outer for loop

public static void main()


Step 0: Start
Step 1: mul ob = new mul()
Step 2: [Link]()
Step 3: Stop

9:
class mirror
void cal()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the no. of rows")
int r = [Link]()
print("Enter the no. of columns")
int c = [Link]()
int a[][] = new int[r][c]
print("Enter the elements")
for(int i = 0; till r, by 1)
for(int j = 0;till c, by 1)
a[i][j] = [Link]()
end of inner for loop
end of outer for loop
print("Original:")
for(int i = 0; till r, by 1)
for(int j = 0; till c, by 1)
[Link](a[i][j])
print()
end of inner for loop
end of outer for loop
print("Mirror:")
for(int i = 0; till r, by 1)
for(int j = c - 1; till 0, by 1)
[Link](a[i][j])
print()
end of inner for loop
end of outer for loop
int a1[] = new int[r]
for(int i = 0; till r, by 1)
for(int j = 0; till c, by 1)
if(j == (c - 1) / 2)
a1[i] = a[i][j]
end of if
end of inner for loop
end of outer for loop

int temp = 0
for(int i = 0; till [Link], by 1)
for(int j = 0; till [Link], by 1)
if(a1[j] > a1[j + 1])
temp = a1[j + 1]
a1[j + 1] = a1[j]
a1[j] = temp
end of if
end of inner for loop
end of outer for loop
print("Sorted elements are:")
for(int i = 0; till [Link], by 1)
[Link](a1[i])
end of for loop

public static void main()


Step 0: Start
Step 1: mirror ob = new mirror()
Step 2: [Link]()
Step 3: Stop

10:
class spiral

Step 1: void doitall()


Scanner sc = new Scanner([Link])
print("Enter the no. of rows")
int r = [Link]()
print("Enter the no. of columns")
int c = [Link]()
int a[][] = new int[r][c]
print("Enter the elements")
String s = ""
for(int i = 0; till r, by 1)
for(int j = 0; till c, by 1)
a[i][j] = [Link]()
end of inner for loop
end of outer for loop

print("Original matrix")
for(int i = 0; till r, by 1)
for(int j = 0; till c, by 1)
print(a[i][j])
print()
end of inner for loop
end of outer for loop
for(int i = r - 2;till r, by 1)
for(int j = 1; till c-1, by 1)
s = s + a[i][j]
end of inner for loop
end of outer for loop
for(int i = r - 3; till 1, by 1)
for(int j = c - 2; till 0, by 1)
s = s + a[i][j]
end of inner for loop
end of outer for loop

s = s + a[r - 2][0]
for(int i = r - 1; till r, by 1)
for(int j = 0; till c, by 1)
s = s + a[i][j]
end of inner for loop
end of outer for loop
for(int i = r - 2; till 0, by 1)
for(int j = c - 1; till c-1, by 1)
s = s + a[i][j]
end of inner for loop
end of outer for loop
for(int i = 0; till 0, by 1)
for(int j = c - 2; till 0, by 1)
s = s + a[i][j]
end of inner for loop
end of outer for loop

print("Spiral one")
print(s)

public static void main()


Step 0: Start
Step 1: spiral ob = new spiral()
Step 2: [Link]()
Step 3: Stop

11:
class trans

void doitall()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the no. of rows")
int r = [Link]()
print("Enter the no. of columns")
int c = [Link]()
print("Enter the elements which are prime no.s")
int a[][] = new int[r][c]
for(int i = 0; till r, by 1)
for(int j = 0; till c, by 1)
a[i][j] = [Link]()
end of inner for loop
end of outer for loop
int co = 0
for(int i = 0;till r, by 1) // prime
for(int j = 0; till c, by 1)
for(int z = 2; till 9, by 1)
if(a[i][j] % z == 0)
if(!(a[i][j] == z))
co++
end of inner if
if(co > 0)
print("no." + a[i][j] + " entered is not prime")
[Link](0)
end of inner if
end of outer if
end of inner for loop
end of outer for loop
int b[][] = new int[r][c]
for(int i = 0; till r, by 1) // transpose
for(int j = 0; till c, by 1)
if(i == j)
b[i][j] = a[i][j]
else
b[i][j] = a[j][i]
end of if else
end of inner for loop
end of outer for loop
print("Transpose is")
for(int i = 0; till r, by 1) // transpose
for(int j = 0; till c, by 1)
[Link](b[i][j])
print()
end of inner for loop
end of outer for loop
String s = ""
String s1 = ""
for(int i = 0;till r, by 1) // boundary and non-boundary elements
for(int j = 0; till c, by 1)
if(i == 0 && j == 0)
s = s + b[i][j]
else if(i == 0 && j == c - 1)
s = s + b[i][j]
else if(i == r - 1 && j == 0)
s = s + b[i][j]
else if(i == r - 1 && j == c - 1)
s = s + b[i][j]
else
s1 = s1 + b[i][j]
end of if else if
end of inner for loop
end of outer for loop
print("Boundary elements are: " + s)
print("Non-Boundary elements are: " + s1)

public static void main()


Step 0: Start
Step 1: trans ob = new trans()
Step 2: [Link]()
Step 3: Stop

12:
class Twelve

void doAll()
Step 1: Scanner sc = new Scanner([Link])
print("Enter the number of names in the first array:")
int a = [Link]()
[Link]() // Consume the newline character
print("Enter the names of the first array:")
String[] s = new String[a]
for (int i = 0; i < a; i++)
s[i] = [Link]()
print("Enter the number of names in the second array:")
int b = [Link]()
[Link]() // Consume the newline character
print("Enter the names of the second array:")
String[] z = new String[b]
for (int i = 0; i < b; i++)
z[i] = [Link]()
String[] c = new String[a + b]
[Link](s, 0, c, 0, a)
[Link](z, 0, c, a, b)
[Link](c, String.CASE_INSENSITIVE_ORDER)
print("Combined and sorted names:")
for (String name : c)
print(name)
public static void main(String[] args)
Twelve ob = new Twelve()
[Link]()

13::
class cons
int n
void input()
Step 1:Scanner sc = new Scanner([Link])
print("Enter the number")
n = [Link]()

void cal()
Step 1:int a = 0
String s = ""
for (int i = 1;till n, by 1)
for (int j = i; till n , by 1)
a = a + j
s = s + j + "+"
end of inner for loop
end of outer for loop
if (a == n)
print(s)
a = 0
s = ""
end of if
public static void main()
Step 0: Start
Step 1:cons ob = new cons()
Step 2:[Link]()
Step 3:[Link]()
Step 4: Stop

14:
class fourteenth
void doall()
Step 1:Scanner sc = new Scanner([Link])
print("Enter the date")
int d = [Link]()
print("Enter the month")
int m = [Link]()
print("Enter the year")
int y = [Link]()
if (d <= 0 || d > 31 || m <= 0 || m > 12)
print("Invalid date")
[Link](0)
else if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
if (d > 31)
print("Invalid date")
[Link](0)

else if (d == 31 && m == 12)


print("Next Day is 01/01/" + (y + 1))
[Link](0)
else if (d == 31)
print("Next Day is 01/" + (m + 1) + (y + 1))
[Link](0)
else
print("Next Day is " + (d + 1) + "/" + (m + 1) + "/" + y)
[Link](0)
end of inner if else if
else if (m == 2)
if (d > 28)
print("Invalid date")
[Link](0)
else
print("Next Day is " + (d + 1) + "/" + (m + 1) + "/" + y)
[Link](0)
end of inner else if
else
if (d > 30)
print("Invalid date")
[Link](0)
else
print("Next Day is " + (d + 1) + "/" + (m + 1) + "/" + y)
[Link](0)
end of inner else if
end of outer else if

public static void main()


Step 0:Start
Step 1:fourteenth ob = new fourteenth()
Step 2:[Link]()
Step 3: Stop

15:
class fifteen
int x
int y
int n
int z

int doit()
Step 1:Scanner sc = new Scanner([Link])
print("Enter the first no.")
x = [Link]()
print("Enter the second no.")
y = [Link]()
double u = 0
for(int i = 1; i <= 20; i++)
u = [Link](x, i) // 2,2=4
for(int j = 1; j <= 20; j++)
if(u == ([Link](y, j)))
n = i
z = j
return n
end of if
return 0

void main()
Step 0: Start
Step 1:fifteen ob = new fifteen()

Step 2: [Link]()

Step 3: int a = [Link]()

Step 4: if(a == 0)

Step 5: print("Not equal at all")

Step 6: else

Step 7: print("The power at which it is equal is for x is " + a + " and for y is "
+ z)
Step 8: Stop

16::

class sixteen
void doall()
Ste 1: int n, pos, x
Scanner s = new Scanner([Link])
print("Enter no. of elements you want in array:")
n = [Link]()
int a[] = new int[n+1]
print("Enter all the elements:")
for(int i = 0; till n, by 1)
a[i] = [Link]()
end f for oop
print("Enter the position where you want to insert element:")
pos = [Link]()
print("Enter the element you want to insert:")
x = [Link]()
for(int i = (n-1); till pos-1, by 1)
a[i+1] = a[i]
end of for loop
a[pos-1] = x
print("After inserting:")
for(int i = 0;till n , by 1)
print(a[i] + ",")
end of for loop
print(a[n])
print()
print("Enter the element you want to remove ")
int elem = [Link]()

for(int i = 0; till [Link],by 1)


if(a[i] == elem)
for(int j = i; till [Link], by 1)
a[j] = a[j+1]
break
end of for loop
print("Elements after deletion ")
for(int i = 0; till [Link] -1, by 1)
print(a[i] + " ")
end of for loop
public static void main()
Step 0: Start
Step 1:sixteen ob = new sixteen()
Step 2: [Link]()
Step 3: Stop

17:

class seventeenth
void cal()
Step 1:Scanner sc = new Scanner([Link])
print("Enter the sentence")
String s = [Link]()
s = s
String str = s
StringTokenizer st = new StringTokenizer(s)
int c = [Link]()
int co = 1
int l = 0
String f = ""
String y = ""
String nn = ""

while (c > 0)
String z = [Link]() //word
if ([Link]() > l)
l = [Link]()
nn = z
if (!(co % 2 == 0))
String h = [Link]([Link]() - 2, [Link]()) //last two letters
String i = [Link](0, [Link]() - 2)
f = f + h + i + " "
co++
c--
else
for (int i = [Link]() - 1; i >= 0; i--)
y = y + [Link](i)
end of if else
f = f + y + " "
co++
y = ""
c--
end of while loop
print("new string after shifting and reversing is " + f)
for (int i = 0; till [Link], by 1)
if ([Link](i) == 'a' || [Link](i) == 'e' || [Link](i) == 'i' || [Link](i)
== 'o' || [Link](i) == 'u')
f = [Link]([Link](i), 'A')
end of if
end of for loop
print("longest word is " + nn)
print("new string after replacing vowels with 'A' is " + f)

int count = 0
print("Palindromes are:")
for (int i = 0; till length, by 1)
for (int j = i; till n, by 1)
String subString = [Link](i, j + 1)
if (check(subString))
count++
print(subString)
end of inner for loop
print("No. of palindromes are " + count)
end of outer for loop
static boolean check(String subS)
int size = [Link]()
for (int i = 0; till size/2, by 1)
if ([Link](i) != [Link](size - i - 1))
return false
end of if
return true
end of for loop
public static void main()
Step 0: Start
Step 1: seventeenth ob = new seventeenth()
Step 2: [Link]()
Step 3: Stop

18:

class eighteeeen
Scanner sc = new Scanner([Link])
void calint()
Step 1: print("Enter the size of the int array")
int n = [Link]()
int a[] = new int[n + 1]
print("Enter the elements of int array")
for (int i = 0; till n, by 1)
a[i] = [Link]()
end of for loop
print("Enter 1 for bubble sort, 2 for selection sort, and 3 for insertion sort for
int array")
int b1 = [Link]()
print("Enter 1 for ascending and 2 for descending")
int z = [Link]()

switch (b1)
case 1
int t = 0
for (int i = 0; till n, by 1)
for (int j = 0; till n, by 1)
if (z == 1)
if (a[j + 1] < a[j])
t = a[j + 1]
a[j + 1] = a[j]
a[j] = t
else
if (a[j + 1] > a[j])
t = a[j + 1]
a[j + 1] = a[j]
a[j] = t
end of if else
end of inner for loop
end of outer for loop
case 2
int small = 0
int pos = -1
for (int i = 0; till n, by 1)
small = a[i]
pos = i
for (int j = i + 1;till n, by 1)
if (z == 1)
if (a[j] < small)
small = a[j]
pos = j
else
if (a[j] > small)
small = a[j]
pos = j
t = a[i]
a[i] = a[pos]
a[pos] = t
end of inner if
end of outer if else
end of inner for loop
end of outer for loop

case 3
for (int i = 1; till n, by 1)
for (int j = i; till 0 , by 1)
if (z == 1)
if (a[j - 1] > a[j])
t = a[j - 1]
a[j - 1] = a[j]
a[j] = t
else
if (a[j - 1] < a[j])
t = a[j - 1]
a[j - 1] = a[j]
a[j] = t
end of if else
end of inner for loop
end of outer for loop
default
print("invalid")
end of switch case
for (int i = 0; till n, by 1)
print(a[i])
end of for loop
void calstring()
Step 1: print("Enter the size of the String array")
int m = [Link]()
String s[] = new String[m]
print("Enter the elements of string array")
for (int i = 0; till m, by 1)
s[i] = [Link]()
end of for loop
print("Enter 1 for bubble sort, 2 for selection sort, and 3 for insertion sort for
string array")
int b2 = [Link]()
print("Enter 1 for ascending and 2 for descending")
int y = [Link]()

switch (b2)
case 1
String t = ""
for (int i = 0; till m, by 1)
for (int j = 0; till m, by 1)
if (y == 1)
if (s[j + 1].compareTo(s[j]) < 0)
t = s[j + 1]
s[j + 1] = s[j]
s[j] = t
else
if (s[j + 1].compareTo(s[j]) > 0)
t = s[j + 1]
s[j + 1] = s[j]
s[j] = t
end of if
end of inner for loop
end of outer for loop
case 2
String small = ""
int pos = -1
for (int i = 0; till m, by 1)
small = s[i]
pos = i
for (int j = i + 1; till m, by 1)
if (y == 1)
if (s[j + 1].compareTo(s[j]) < 0)
small = s[j]
pos = j
else
if (s[j + 1].compareTo(s[j]) > 0)
small = s[j]
pos = j
end of if
t = s[i]
s[i] = s[pos]
s[pos] = t
end of inner for loop
end of outer for loop
case 3
for (int i = 1; till m, by 1)
for (int j = i; till 0, by 1)
if (y == 1)
if (s[j - 1].compareTo(s[j]) > 0)
t = s[j - 1]
s[j - 1] = s[j]
s[j] = t
else
if (s[j - 1].compareTo(s[j]) < 0)
t = s[j - 1]
s[j - 1] = s[j]
s[j] = t
end of if
end of inner for loop
end of outer for loop
default
print("invalid")
end of switch case
for (int i = 0; till m, by 1)
print(s[i])
end of for loop
void main()
Step 0: Start
Step 1: eighteeeen ob = new eighteeeen()
Step 2: [Link]()
Step 3: [Link]()
Step 4: Stop

19:
class nineteenth

void words()
Step 1:Scanner sc = new Scanner([Link])
print("Enter the sentence")
String str = [Link]()
int wCount = 0
int uCount = 0
int vCount = 0
String z = str
z = z + " "

for (int i = 0; till [Link], by 1)


char c = [Link](i)
end of for loop
switch (c)
case ' ':
case '.':
wCount++

switch (c)
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
vCount++

if (c >= 65 && c <= 90)


uCount++
end of if
print("Number of words = " + wCount)
print("Number of vowels = " + vCount)
print("Number of upper case characters = " + uCount)

int len = [Link]()


char seenArr[] = new char[len]
int freqArr[] = new int[len]
int d = 0
for (int i = 0; till len, by 1)
char ch = [Link](i)
end of for loop
if ([Link](ch))
continue
end of if
boolean seen = false
for (int j = 0; till d, by 1)
if (ch == seenArr[j])
seen = true
break
end of if
if (seen)
continue
end of if
end of for loop
int f = 1
for (int k = i + 1; till len, by 1)
if (ch == [Link](k))
f++
end of if
seenArr[d] = ch
freqArr[d] = f
d++
end of for loop
for (int i = 0; till d, by 1)
print(seenArr[i] + " ")
println()
end of for loop
for (int i = 0; till d, by 1)
print(freqArr[i] + " ")
end of for loop

public static void main(String args[])


Step 0: Start
Step 1: nineteenth obj = new nineteenth()
Step 2: [Link]()
Step 3: Stop

20:
class twenty
void cal()
Step 1:Scanner sc = new Scanner([Link])
print("Enter the no. of rows of matrix")
int r1 = [Link]()
print("Enter the no. of columns matrix")
int c1 = [Link]()
int a1[][] = new int[r1][c1]
print("Enter the elements")
for (int i = 0; till r1, by 1)
for (int j = 0; till c1, by 1)
a1[i][j] = [Link]()
for (int i = 0; i < r1; i++)
for (int j = 0; j < c1; j++)
print(a1[i][j])
println()
int h = 0
int c = 1
for (int i = 0; i < [Link]; i++)
h = a1[0][i]
for (int j = 0; j < [Link]; j++)
if (a1[j][i] > h)
h = a1[j][i]
print("Highest element from " + c + "th column is " + h)
c++
int l = 0
for (int i = 0; i < [Link]; i++)
l = a1[i][0]
for (int j = 0; j < [Link]; j++)
if (a1[i][j] < l)
l = a1[i][j]
print("Lowest element from " + i + "th row is " + l)
for (int i = 0; i < a1[0].length; i++)
int t = a1[0][i]
a1[0][i] = a1[r1 - 1][i]
a1[r1 - 1][i] = t
print("After swapping")
for (int i = 0; i < r1; i++)
for (int j = 0; j < c1; j++)
print(a1[i][j])
println()
public static void main()
twenty ob = new twenty()
[Link]()

You might also like