pattern program in java for"HELLO'
Answers
Answer:
public class Type
{
public static void main (String [] args)
{
System.out.println("Hello ")
}
}
Explanation:
I have not inserted any package .
hope it helped you¯\_(ツ)_/¯
Answer:
import java.util.Scanner;
public class Edureka
{public static void main(String[] args) {
char[] letter = { 'H','E','L','L','O, };
int letter_number = 0;
String[] diamond = new String[26]; // array of strings
try {
char user_letter = reader.next("[A-Z]").charAt(0);
// search for letter number in the array letter
for (int i = 0; i < letter.length; i++) {
if (letter[i] == user_letter) {
letter_number = i;
break;
}
}
// construct diamond
for (int i = 0; i <= letter_number; i++) {
diamond[i] = "";
// add initial spaces
for (int j = 0; j < letter_number - i; j++) {
diamond[i] += " ";
}
// add letter
diamond[i] += letter[i];
// add space between letters
if (letter[i] != 'A') {
for (int j = 0; j < 2 * i - 1; j++) { diamond[i] += " "; } // add letter diamond[i] += letter[i]; } // Draw the first part of the diamond System.out.println(diamond[i]); } for (int i = letter_number - 1; i >= 0; i--)
{
// Draw the second part of the diamond
// Writing the diamondArray in reverse order
System.out.println(diamond[i]);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
reader.close();
}
}
}
Explanation: