JAVA Program
JAVA Program to Find the Output.
Q.1 Find the Outptut
class Pattern1 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print(“* “);
}
System.out.println();
}
}
}
Q.2 Find the Outptut
class Pattern2 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n – i – 1; j++) {
System.out.print(” “);
}
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i || i == n – 1) {
System.out.print(“* “);
} else {
System.out.print(” “);
}
}
System.out.println();
}
}
}
Q.3 Find the Outptut
class Pattern3 {
public static void main(String args[]) {
int n = 5;
for (int i = n – 1; i >= 0; i–) {
for (int j = 0; j < n – i – 1; j++) {
System.out.print(” “);
}
for (int j = 0; j <= i; j++) {
System.out.print(“* “);
}
System.out.println();
}
}
}
Q.4 Find the Outptut
class Pattern4 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(“* “);
}
System.out.println();
}
}
}
Q.5 Find the Outptut
class Pattern5 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == 0 || i == n – 1 || j == 0 || j == n – 1) {
System.out.print(“* “);
} else {
System.out.print(” “);
}
}
System.out.println();
}
}
}
Q.6 Find the Outptut
class Pattern6 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print(“* “);
}
System.out.println();
}
}
}
Q.7 Find the Outptut
class Pattern7 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = n; j > i + 1; j–) {
System.out.print(” “);
}
for (int j = 0; j <= i; j++) {
System.out.print(“* “);
}
System.out.println();
}
}
}
Q.8 Find the Outptut
class Pattern8 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = n – i – 1; j > 0; j–) {
System.out.print(” “);
}
for (int j = 0; j < n; j++) {
System.out.print(“* “);
}
System.out.println();
}
}
}
Q.9 Find the Outptut
class HalfDiamondPattern {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print(“* “);
}
System.out.println();
}
for (int i = n – 1; i > 0; i–) {
for (int j = 0; j < i; j++) {
System.out.print(“* “);
}
System.out.println();
}
}
}
Q.10 Find the Outptut
class Pattern10 {
public static void main(String args[]) {
int n = 5;
for (int i = 0; i < n; i++) {
int number = 1;
for (int j = 0; j <= i; j++) {
System.out.print(number + ” “);
number = number * (i – j) / (j + 1);
}
System.out.println();
}
}
}
Q.1 Find the Outptut
public class1 {
public static void main(String[] args) {
System.out.println(“Hello, World!”);
}
}
Q.2 Find the Output
public class2 {
public static void main(String[] args) {
int a = 5;
int b = 7;
int sum = a + b;
System.out.println(“Sum: ” + sum);
}
}
Q.3 Find the Output
public class3 {
public static void main(String[] args) {
int a = 3;
int b = 4;
int product = a * b;
System.out.println(“Product: ” + product);
}
}
Q.4 Find the Output
public class4 {
public static void main(String[] args) {
int a = 10;
int b = 2;
int quotient = a / b;
System.out.println(“Quotient: ” + quotient);
}
}
Q.5 Find the Output
public class5 {
public static void main(String[] args) {
String firstName = “John”;
String lastName = “Doe”;
String fullName = firstName + ” ” + lastName;
System.out.println(“Full Name: ” + fullName);
}
}
Q.6 Find the Output
public class6 {
public static void main(String[] args) {
int number = 15;
if (number % 2 == 0) {
System.out.println(“Even”);
} else {
System.out.println(“Odd”);
}
}
}
Q.7 Find the Output
public class7 {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
System.out.println(“Iteration: ” + i);
}
}
}
Q.8 Find the Output
public class8 {
public static void main(String[] args) {
int i = 1;
while (i <= 5) {
System.out.println(“Iteration: ” + i);
i++;
}
}
}
Fun & Easy to follow
Works on all devices
Your own Pace
Super Affordable
Popular Videos
Play Video
UX for Teams
Learn the basics and a bit beyond to improve your backend dev skills.
Chris Matthews
Designer
Play Video
SEO & Instagram
Learn the basics and a bit beyond to improve your backend dev skills.
Chris Matthews
Designer