+ 3
How to print 1 2 3 3 4 5 4 5 6 7 pattern in java?
11 Answers
+ 23
//input 4
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int lng = inp.nextInt();
int i = 1;
while (i <= lng) {
int ii = 0;
while(ii < i) {
System.out.print((ii+i)+" ");
ii++;
}
System.out.print("\n");
i++;
}
}
}
+ 20
//input 4
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int lng = inp.nextInt();
for (int i = 1; i <= lng; i++) {
for (int ii = 0; ii < i; ii++) {
System.out.print((ii+i)+" ");
}
System.out.print("\n");
}
}
}
+ 19
//Well... If you only need this specific output... ^_^
System.out.println("1\n2 3\n3 4 5\n4 5 6 7");
+ 18
"While" loop?!?! Why didn't you say it earlier?!?! Your question was incomplete... ~_~
+ 16
Can't figure out the algorithm... /;
+ 4
public class Program
{
public static void main(String[] args) {
int k = 1;
for(int i = 1; i <= 5; i++){
for(int j = 1; j < i; j++){
System.out.print(k);
k++;
}
System.out.println();
}
}
}
+ 3
You cannot write a code to solve this for other numbers, it seems the numbers do not follow a specific order, so:
String [] nums = {"1", "23", "345", "4567"};
for (String s : nums){
System.out.println(s);
}
+ 2
What do you mean?
+ 2
1
2 3
3 4 5
4 5 6 7
I want this output
+ 1
//Well... If you only need this specific output... ^_^
System.out.println("1\n2 3\n3 4 5\n4 5 6 7");
thnks but using while loop print this pattern
+ 1
https://code.sololearn.com/c57dF3qYxw3i/?ref=app check this out