0% found this document useful (0 votes)
44 views6 pages

String Pattern Solved Odf

The document contains 6 Java programs that print strings in different patterns. The programs take a string as input and use for loops to print the characters in the string in descending or ascending order on successive lines. This allows the string to be displayed as a triangular pattern. The programs demonstrate different approaches to print the characters of a string in triangular format using basic string and looping operations in Java.

Uploaded by

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

String Pattern Solved Odf

The document contains 6 Java programs that print strings in different patterns. The programs take a string as input and use for loops to print the characters in the string in descending or ascending order on successive lines. This allows the string to be displayed as a triangular pattern. The programs demonstrate different approaches to print the characters of a string in triangular format using basic string and looping operations in Java.

Uploaded by

Sandipan Bhuina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

COMPUTER APPLICATION

PROGRAM ON STRING PATTERN


PROGRAM:

/*

B
BL
BLU
BLUE
BLUEJ
*/

import java.util.*;
class p2 {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter String :");
String str = in.nextLine();
int l=str.length();
char ch;
for(int i=0;i<l;i++) {
for(int j=0;j<=i;j++) {
ch=str.charAt(j);
System.out.print(ch);
}
System.out.println();
}
2

/*
BLUEJ
BLUE
BLU
BL
B
*/
import java.util.*;
class a31 {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter a Word.");
String str = in.nextLine();
int l=str.length();
for(int i=l-1;i>=0;i--) {
for(int j=0;j<=i;j++) {
System.out.print(str.charAt(j));
}
System.out.println();
}
}
}
3

/*
B
LL
UUU
EEEE
JJJJJ

*/
import java.util.*;
class p1 {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter String :");
String str = in.nextLine();
int l=str.length();
char ch;
for(int i=0;i<l;i++) {
for(int j=0;j<=i;j++) {
ch=str.charAt(i);
System.out.print(ch);
}
System.out.println();
}
}
4

/*
BLUEJ
LUEJ
UEJ
EJ
J
*/
import java.util.*;
class V31c {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter Word:");
String str = in.nextLine();
int l=str.length();
for(int i=0;i<l;i++) {
for(int j=i;j<l;j++) {
System.out.print(str.charAt(j));
}
System.out.println();
}
}
}
5

/*
J
EE
UUU
LLLL
BBBBB
*/
import java.util.*;
class b31 {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter String :");
String str = in.nextLine();
int l=str.length();
for(int i=l-1;i>=0;i--) {
for(int j=l-1;j>=i;j--) {
System.out.print(str.charAt(i));
}
System.out.println();
}
}
}
6
/*
B
LB
ULB
EULB
JEULB
*/

import java.util.*;
public class StringPatt
{
public static void StringPat()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a String = ");
String n = sc.nextLine();
int l = n.length();
for(int i=0;i<l;i++)
{
for(int j=i;j>=0;j--)
{
char ch = n.charAt(j);
System.out.print(ch+" ");
}
System.out.println();

You might also like