Write two separate programs to generate the following patterns.
11111
11112
11123
11234
12345
Answers
Answered by
4
CODE 1:-
/*
11111
1111
111
11
1
*/
class series5
{
public static void main(String[] args)
{
for(int a=1;a<=5;a++)
{
int k=1;
for(int b=a;b<=5;b++)
{
System.out.print(k);
}
System.out.println();
}
}
}
___________________________
CODE 2:-
/*
1
12
123
1234
12345
*/
class series6
{
public static void main(String[] args)
{
for(int a=1;a<=5;a++)
{
for(int b=1;b<=a;b++)
{
System.out.print(b+" ");
}
System.out.println();
}
}
}
___________________________________
Important Point:-
- Always try to give shortest answer while Coding any program.
- Use Scanner class Or Buffer reader to ensure input through Keyboard means direct on Output screen.
- Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double, etc. and strings through keyboard. It is the easiest way to read input in a Java program.
- Always divide double data type variable with integer or integer data type from double data type variable.To ensure 100% result.
__________________________
Note:-
Codes are confirmed by Blue j compiler .
Similar questions