Home Answers Viewqa Java-Beginners how to print in a pattern in java

 
 


Amit Desai
how to print in a pattern in java
1 Answer(s)      7 months ago
Posted in : Java Beginners

how to print this pattern? 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7

View Answers

October 20, 2012 at 4:25 PM


Here is a code that displays the following pattern:

 1  2  3  4
 12 13 14 5
 11 16 15 6
 10 9  8  7

public class spiral{
    public static void main(String[] args) {
        int n=4;
        int a[][]=new int[n][n];
        int i,j,x=1,p=0,q=n-1;
        while(x<=(n*n))
        {
            for(i=p;i<=q;i++)
            {
                a[p][i]=x;
                x++;
            }
            for(i=(p+1);i<=q;i++)
            {
                a[i][q]=x;
                x++;
            }
            for(i=(q-1);i>=p;i--)
            {
                a[q][i]=x;
                x++;
            }
            for(i=(q-1);i>=(p+1);i--)
            {
                a[i][p]=x;
                x++;
            }
            p++;
            q--;
        }
        for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
            {
                System.out.print(a[i][j]+" ");
            }
            System.out.println();
        }
    }
}









Related Pages:
Pattern
Pattern  How to print this pattern in Java please help me A AC ACE ACEG ACEGI The program should be right to left
print rectangle pattern in java
print rectangle pattern in java  * * * * * * * how to generate this pattern in java??   Hi friend try this code may this will helpful for you public class PrintRectangle { public static void main
How to print the following pattern in java?
How to print the following pattern in java?  How to print the following pattern in java? he he is he is going he is going in   import java.io.*; class StringPattern { public static void main(String[] args
how to print the following pattern
how to print the following pattern  Hello hEllo heLlo helLo hellO pls reply soon its an emergency   class StringPattern { public static void main(String[] args) { String st="hello
pattern
and a pattern size only between 2 and 9. You are print the menu and the user's response...pattern  write a java program that can create four different patterns of different sizes. The size of each pattern is determined by the number
How to print this in java?
How to print pattern in Java?  How to print a particular pattern in Java...;  How to print this in java
Pattern Making
Pattern Making  how to print this pattern in java? * * * * * * * * * * * * * * * * * It is just an example
print
print  How to print JFrame All Componant?   Please visit the following link: http://www.roseindia.net/java/example/java/swing/Print.shtml
pattern java example
pattern java example  how to print this 1 2 6 3 7 10 4 8 11 13 5 9 12 14 15
pattern program
pattern program  can any 1 print the following pattern in java .plz give the code.and yes thank u so much for answering my 2 other questions.had i... before.anyways the pattern goes like this abcdcba abc cba ab ba a a ab ba abc abc
print the below pattern
print the below pattern  to write a program using a function ti initialize a character 'A' and print the following pattern of characters upto six lines A A B A B C A B C D A B C D E A B C D E F
Pattern
Pattern  1234321 123 321 12 21 1 1 please,give me this pattern in java   class Sixth_1 { public static void main(String args...; } } }   Here is a number pattern class Pattern{ public
how to print - Java Beginners
how to print  how to print something on console without using System.out.print() method ?  Hi Friend, You can use PrintWriter to write anything on the console. import java.io.*; public class Print{ public static
singleton pattern - Java Beginners
singleton pattern  how i use singleton pattern in my web aplication project.plz give an example.its urgent
Print
Print  In system.out.println,what meant ln..?   System: It is a class made available by Java to let you manipulate various operating system... into the stream and, as opposed to print() method, gets you to the new line after the text
how to write a program in java to print numbers in equalateral triangle
how to write a program in java to print numbers in equalateral triangle  the output must be 1 324 76589   Here is an example of pattern 1 2 3 4 5 6 7 8 9 Example: public class NumberTriangle{ public
how to print pdf format
how to print pdf format  Hi every body iam doing school project iam using backend as oracle front end java .how to print student marks list /attendence in pdf format. please help me. thanks in advance.   Here
Design pattern - Java Beginners
Design pattern  How to make a java program to check the java program is already started if started the execution then dont allow the new program to start
Print Form - Java Beginners
Print Form  Hello Sir I have Created Admission Form when user fills data and submit that data to access database,then when i Click on PRINT Button I want to get Print of that forms Contents,How I can Do it with JAVA SWING,plz
how to print from right to left in java????
how to print from right to left in java????   can anyone pls tell how to print from right to left in java
logic for pattern program
logic for pattern program  what's the logic for create pattern program how can i create any pattern program with in minute. like this 123454321... create this program in java without help whats the logic how can i understand
print a rectangle - Java Beginners
print a rectangle  how do I print a rectangleof stars in java using simple while loop?Assuming that the length n width of the rectangle is given.  Hi friend, I am sending running code. import java.io.
Print in a long paper - Java Beginners
Print in a long paper  how to print text in long paper?? each print text, printer stops. not continue until the paper print out. Thanks
Print the following format
Print the following format  how to print the following format given string "00401121" in java 0-** 1-* 2-* 3- 4
Java create triangle pattern
Java create triangle pattern In this tutorial, you will learn how to create...(" how many lines you want to print? "); nline= read.nextInt...); } } } Output: how many lines you want to print? 5 what is the symbol you want
How to Print a Stack Trace Message
How to Print a Stack Trace Message  Debugging of Java program requires... times you have to print the detailed error message on the console... will print the detailed message on the console. You can use
print hello n hi
print hello n hi  how to write a java program that prints "hello" 5 times, "hi" 1 time n again "hello" 4 times..?? do reply
Adapter Pattern
by which Adapter can be implemented. The above example shows how Adapter pattern... Adapter Pattern       This pattern establishes a relationship between the two unrelated interfaces
how to make this pattern???
how to make this pattern???  how to make following pattern in javascript
how to print on pre-printed cheque - Development process
how to print on pre-printed cheque  I want to print on pre-printed cheques using java and jsp .please provide me the source code which help me to resolve this problem
Java Reverse String Pattern
Java Reverse String Pattern In this section, we have displayed a string in reverse pattern. For this,we have specified a string which is first converted into character array and then print it. Then we have reversed the string using
Design Pattern
to demonstrate that how observer pattern works, for this, the example creates two windows...Design Pattern           Observer Design Pattern This design pattern defines one
How to print list of files in client system
How to print list of files in client system  have some list of files in server.i just want to print that files in client machine with out opening... need to come from client system. but i done this functionality in java
Bridge Pattern
in javaHow many types of exception handling are there in java... are there in java? ~~~~~~~~~~~~~~~~~~~~~~~~ The above example tries to show how... Bridge Pattern      
Strategy Pattern of HashCode Equality
Pattern and how Java works with dynamic proxies... Strategy Pattern of HashCode Equality     2005-05-18 The Java Specialists' Newsletter [Issue 109] - Strategy Pattern of HashCode Equality
dotmatrix print with JasperReports - Development process
dotmatrix print with JasperReports  Hello, I was wondering how to print to a dotmatrix printer from a swing application. I also have to see a print preview of the page. Is this possible with Java, or maybe JasperReports
how to print crystal report from java - Java Beginners
how to print crystal report from java  I want to know -way to print crystal report from java? -which jar are needed to import? I am new at java... for Java: * Expedite data connectivity and formatting using an intuitive design
Print the URL of a URLConnection
Print the URL of a URLConnection       In this section we are going to describe, how to retieve...:\roseindia>javac printURLConnection.java C:\roseindia>java
Clear the print button after onclicking the print - JSP-Servlet
Clear the print button after onclicking the print  rate_print.document.writeln(" "); hai sir, this is my java script code, i ask how to clear the printbutton image when after onclicking the print button....  Hi
pattern program
pattern program  13579 1357 135 13 1 pattern program in java   Here is your Example:- package Compare; public class PatternDemo { public static void main(String [] args){ int c=10; for(int i=0;i<
How to print different Messge for the same NumberFormatException on different cause objects in JAVA?
How to print different Messge for the same NumberFormatException on different cause objects in JAVA?  How to print different Messge for the same NumberFormatException on different cause objects in JAVA? try { int
Print Screen Using Java Swing
Print Screen Using Java Swing       In this section, you will learn how to print in java swing. The printable that is passed to setPrintable must have a print method
how to print the server time
how to print the server time  how to print the server time in jsp and update time in fix interval
pattern generation
pattern generation  write a program to print pattern shown below 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9   Here is an example of number spiral. public class NumberSpiral{ public
print 100 numbers using loops
print 100 numbers using loops  how to print from 1 to 100 using...;a++) { System.out.println("val of a is ="+a); } } }   How java is securable ?   why java is securable
Print Only Forms Contents - Java Beginners
Print Only Forms Contents  Hello Sir I Have Created Simple Registration Form with Database Connectivity, Now I Want To Print Registration form Contents ,How I can Do that, plz Help Me  Hi Friend, Please go through
how to print the server time
how to print the server time  i want to print database time in clintside and update time in every secound without creating connection to database for each time. how can i do
diamond print
diamond print   print the pattern 1 2 3 4 5 6 7 8 9 10 11 12
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012
date print
date print  how can i print the date in jsp page in the following formate month-date-year. (example. march 8 2012

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.