Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

i want pattern in abcd 1234 bcde 2345

+1 vote
asked Oct 8, 2021 by Bhaswat Panigrahi (130 points)
/******************************************************************************

                            Online Java Compiler.

                Code, Compile, Run and Debug java program online.

Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

import java.util.*;

public class Main

{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

int i = 1;

while(i<=n){

int val = 1;

int j = 1;

while(j<=n){

     if(i%2==0){

         

     System.out.print(val);

     val++;

     }else{

         char letter = (char)('A'+j-1);

         System.out.print(letter);

         letter++;

     }

     j++;

}

System.out.println();

i++;

}

}

}

1 Answer

0 votes
answered Oct 9, 2021 by Peter Minarik (86,040 points)

Please, provide an exact definition of what you would like to do. For what input, what is the expected output? Maybe provide some examples.

Without knowing what exactly you wanted, I created the following code.

This takes a number n, and displays the first n positive numbers. Then the line below the first n capital letters (starting from 'A').

The next two lines are the same as above, but starting with one offset (numbers starting from 2, letters from 'B').

The next two lines with an offset of two and so on.

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++)
        {
            int val = i;
            for (int j = 0; j < n; j++)
                System.out.print(val + j + 1);
            System.out.println();

            for (int j = 0; j < n; j++)
                System.out.print((char)('A' + val + j));
            System.out.println();
        }
    }
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...