0% found this document useful (0 votes)
14 views4 pages

Print The Following Pattern Using 1) For 2) While Using While Loop: Public Class Public Static Void Int Int While

The document provides code examples to print a pattern using a while loop and a for loop in Java. It also shows an example of inheritance in Java by creating an abstract Math class with static and non-static members, and a work class that extends Math and overrides its methods.

Uploaded by

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

Print The Following Pattern Using 1) For 2) While Using While Loop: Public Class Public Static Void Int Int While

The document provides code examples to print a pattern using a while loop and a for loop in Java. It also shows an example of inheritance in Java by creating an abstract Math class with static and non-static members, and a work class that extends Math and overrides its methods.

Uploaded by

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

Print the following pattern using 1)for 2)while

USING WHILE LOOP:

public class Pattern2 {

public static void main(String[] args) {


int i=1;int j;
while(i<5)
{
j=1;
while(j<=i)

{
System.out.print(i);j++;
}
i++;
System.out.println();
}
}

Using FOR LOOP:


public class Assign {

public static void main(String[] args) {


for (int i=1;i<=4;i++)
{

for(int j=1;j<=i;j++)
{
System.out.print(i);
}
System.out.println();
}

}
}

import java.io.*;
abstract class Math
{
static int a=5;
double b=2.5;
abstract void add();
void multiply()
{
System.out.print("the multiplication value is ");
System.out.println(a*b);
}
void division()
{
System.out.print("the division answer is ");
System.out.println(a/b);
}
}
public class work extends Math
{
int x=10;
void add()
{
System.out.print("the added value is ");
System.out.println(x+a);
}
void multiply()
{
System.out.print("the multiplication value is ");
System.out.println(x*a);
}
void division()
{
System.out.print("the division answer is ");
System.out.println(x/a);
}
public static void main(String[] args)
{
work a=new work();
work b=new work();
work c=new work();
a.add();
b.multiply();
c.division();
}
}

You might also like