0% found this document useful (0 votes)
2 views

JAVA ANS

The document contains two Java programs: the first program generates a specific cross pattern based on a given string, while the second program creates a star pattern based on an integer input. Both programs utilize methods for printing spaces and characters in a structured format. They demonstrate the use of loops and conditional statements to achieve the desired output patterns.

Uploaded by

emptybags06
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)
2 views

JAVA ANS

The document contains two Java programs: the first program generates a specific cross pattern based on a given string, while the second program creates a star pattern based on an integer input. Both programs utilize methods for printing spaces and characters in a structured format. They demonstrate the use of loops and conditional statements to achieve the desired output patterns.

Uploaded by

emptybags06
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
You are on page 1/ 2

OMEGA CROSS

import java.util.*;
public class Main
{
public static void pg(int g){
for(int i=0;i<g;i++){
System.out.print(" ");
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String str = s.nextLine();
int len = str.length();
int g1 = 0, g2 = len - 2;
for(int i=0;i<len/2;i++){
pg(g1);
System.out.print(str.charAt(i));
pg(g2);
System.out.print(str.charAt(len-i-1));
pg(g1);
System.out.println();
g1++;
g2-=2;
}
for(int i=len/2;i>=0;i--){
pg(g1);
if(str.charAt(i) == (str.charAt(len-i-1))){
System.out.print(str.charAt(i));
}
else{
System.out.print(str.charAt(i));
pg(g2);
System.out.print(str.charAt(len-i-1));
}
pg(g1);
System.out.println();
g1--;
g2+=2;
}

}
}
-----------------------------------------------------------------------
PATTERN

import java.util.*;
public class Main
{
public static void pg(int g){
for(int i=0;i<g;i++){
System.out.print(" ");
}
}

public static void ps(int s){


for(int i=0;i<s;i++){
System.out.print("* ");
}
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int g = -3;
for(int i=n;i>=1;i--){
if(g==-3){
ps(2*n - 1);
}
else{
ps(i);
pg(g);
ps(i);
}
g+=6;
System.out.println();
}
g-=12;
for(int i=2;i<=n;i++){
if(g==-3){
ps(2*n - 1);
}
else{
ps(i);
pg(g);
ps(i);
}
g-=6;
System.out.println();
}
}
}

You might also like