} 20 28 36 I also calculate the number of spaces we'll need on the left hand side of the first row with spaces. Based on the input from user, we used the binary search to check if the element is present in the array. At the end of the program, we have added compiler such that you can execute the below codes. 65432 4 4 4 4 System.out.println(); In the above code, the pyramid pattern is built using a nested for loops. 4 8 11 13 12***** { The code uses the Scanner class from the java.util package to read the password from the user's input. *543212345* 1 rev2023.3.3.43278. An example of data being processed may be a unique identifier stored in a cookie. At the end of each row, we print rowCount value rowCount times. 8. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well. Update the grid state based on the user's input and display the updated grid. 0 Variable i indicates the number of rows, variable j indicates the number of columns, and rows is used to take input from the user. 212 Enter the Limit: 5 for(int j=1;j1) { We will also look into some examples of creating inverted pyramid pattern in java program. }, how to print ***** 5 * * int temp=num; m=f*m; Here we will print the full pyramid for n lines. * * * * *, public static void main(String []args){ The pyramid is one of the simple pattern programs in Java that is often asked in interviews. for(int j = 1 ; j<=Countrow; j++){ 12345** 9 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 9 How to print alphabet pyramid starting with user input and descending? To understand this example, you should have the knowledge of the following Java programming topics: Add Two Matrix Using Multi-dimensional Arrays, Determine the name and version of the operating system. This will be the number of rows he wants in a pyramid. In the above pyramid program in java, first, we will take the input from the user for the number of rows. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. 1. * * 0 2 4 6 8 10 12 14 16 0 2 4 6 8 10 12 14 16 int i=1,j,n=7; } Pyramid Pattern Programs in Java Here I am providing some examples to create different pyramid patterns from numbers, symbols etc. { Why are Suriname, Belize, and Guinea-Bissau classified as "Small Island Developing States"? } Here is the function to print pattern 2. for row in range(1,6): So if the user entered 5, this is what it should look like: So the number of spaces on the first line is four, the second one has three spaces, and so on until you get to zero. 5 4 3 2 1 * for input 10 System.out.print(k + " " ); l=l+k ; Enter element to be searched: 6 Element found at index 3. { } 2 1 Please enter an even number for the width of the house (must be odd numbers and bigger than 1): 5, How to print the below pattern using Java If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. * 7 8 9 0 1 2 3 4 3 2 1 0 9 8 7 And, inside the loop, we can create another loop to iterate 7 times (7 days). } Connect and share knowledge within a single location that is structured and easy to search. More than 15 pattern programs using star, are included in this article. * 6 7 8 9 0 1 2 1 0 9 8 7 6 System.out.println(); 10000000 1. 0 2 i=i-2; Mail us on [emailprotected], to get more information about given services. This is useful, as we can create the while loop, which states that we should continue to print the tree while the current middle character is less than or equal to the input character. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. 1 2 3 How should I go about getting parts for this bike? 123456* It's mostly right, but you are starting the loops from 1, but they really should be starting from 0, and the condition in the for loops shouldn't have == which just makes it run once. System.out.print("*"); * 4 5 6 7 8 7 6 5 4 212 In this article, we have discussed what square pyramidal number in Java is, an example to understand the logic behind it, a Java program to identify a pyramidal number, Java programs for different pyramid patterns of numbers. } * 2 3 2 1 public static void main(String g[]) print *(level-x), (str(x)+ )*x *; Developed by JavaTpoint. { { The above image is an example of a full pyramid pattern using the symbol *. Your email address will not be published. 2 2 After that, we will run an outer for loop from 1 to rows and we will run an inner for loop from 1 to i where i is the current row number. * * output = output + ((16 * x) + fixedNum); OUTPUT LONGEST ODD LENGTH WORD IS CHARACTER The number of for loops depends on the pattern of the pyramid. In the above pyramid program in java, first, we will take the input from the user for the number of rows. Required fields are marked *. In this program, you'll learn to create pyramid, half pyramid, inverted pyramid, Pascal's triangle and Floyd's triangle sing control statements in Java. Printing pascal pattern triangle in Java. All examples are given above using a loop. Get two arrays as the input from the user and check whether it is the same or not. Step 3: This code is a simple Java program that asks the user to input a password, and then verifies whether the input password is equal to the expected password "1234". for(j=1;j<=i;j++) for(int k=i;k<=n;k++) 7 7 7 7 7 7 7 Notice that every row has 2*r-1 numbers. Scanner num=new Scanner(System.in); a b a I can't seem to figure out how to put these FOR loops together to make this work as instructed. //Printing i spaces at the beginning of each row In the above pyramid program in java, first, we will take the input from the user for the number of rows. System.out.print("* "); { ******* If you have questions, feel free to ask. return pyramid, Awesome Post Sir Very clean explanation.thanks for sharing the article, how will i get the pattren 6 in * & * & * & * &, for(int i=0;i=i;j++){ }, Public static void main(String args[]){ We and our partners use cookies to Store and/or access information on a device. 5. #######**** //Implementing the logic Pyramid patterns are very popular and once we get the logic on the way its created, writing code to achieve the same is an easy task. It returns true if the character is an alphabet and else it returns false.. } else { { System.out.print(Enter a number: ); 3 2 1 2 3 4321234 // }, How Many Rows You Want In Your Pyramid? Then the numbers are starting from 1 to i and then to 1 again. 0 2 4 6 8 10 12 14 16 18 20, Notes: In this section, we will learn what is a pyramidial number and also create Java programs to check if the given number is a pyramidial number or not. How can i print this pattern? 20 Write a program to display inverted full pyramid star pattern. k; To understand this example, you should have the knowledge of the following Java programming topics: Java for Loop Java if.else Statement System.out.print(*); 32123 For each letter we have to add: we print the word and then add the new letter in the middle of the word. } 1234567 2 2, class Pattern22 In your case the conditions don't really make sense. }, Hey its quite simple. * 2 * Can anyone solve me this? { else for(j=m; j=m; k){ Full Stack Development with React & Node JS(Live) Java Backend Development(Live) React JS (Basic to Advanced) JavaScript Foundation; Machine Learning and Data Science. 1,3,3,1 int l,s,no; 21 7 6 5 4 3 2 1 2 3 4 5 6 7 Interesting coding exercise. This code will use onclick () to call a specific function that can display a pyramid made of star using for () loop by nesting the value of the main loop. } * 9 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 9 1 1, how to print the pattern 2 3 4 3 2 and spreading knowledge. The code for the above pattern is,if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'knowprogram_com-leader-2','ezslot_12',141,'0','0'])};__ez_fad_position('div-gpt-ad-knowprogram_com-leader-2-0'); If you enjoyed this post, share it with your friends. 212 for(j=i;j<=row; j++){ Example 1: Java Nested for Loop 7890123210987 This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License. * * (My loop isn't working). no; { 2 1 2 Take the size of the pyramid from the user as input. Enter the size of second array: 3. public static void main(String[] args) { 1 1 1 2 1 How to draw Khayyams triangle (also known as Pascals triangle) in Java till 6 rows? int row=11; Output. At the beginning of each row, we print 'i' spaces where 'i' will be value from noOfRows to 1. def pyramid(): The base of the Pyramid will be the widest and will start converging towards the top where there will only be one element. I just added them for spacing: Enter a single letter (Enter alphabet to display Pyramid): E. I stripped down your program to the core algorithm that is at work: Printing the tree. So, I really needed this to help with my math homework and it was super helpful. System.out.print(k++); } Step 1: First, we will declare three variables of integer data type: i, j, and rows. } * 5 6 7 8 9 0 9 8 7 6 5 please help me on print the characters in alphabet symbol Z, import java.util. In this problem, at the end of each row we print j where j value will be from i to noOfRows and from noOfRows-1 to i. very good example send me some more examples above email, very nice and good to understand all the concepts very easily teet by teet and beat by beat, The 4 program of the liSt in the page the second for loop is not work correctly please explain the second system.out.print (j+ ), it prints the value of J and the number of characters to be skipped, Its awesome its a great useful idea thanks, Can you please help me to solve this problem */ Write a Java program to display the half pyramid star pattern. 5432 System.out.print(i); } } System.out.println(); String formated = (i==count)? { for(j=1;j<=i;j++) Disconnect between goals and daily tasksIs it me, or the industry? How to read characters in a string in java. please be sending some of this things to my email. Mainly the, Generate Alphabetic Pyramid based on user input, How Intuit democratizes AI development across teams through reusability. } 0 2 4 6 8 { 3 2 1 2 3 The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. System.out.println(" "); no=l; } ; The first for loop prints spaces before the stars, equal to size - row number. 6 7 8 9 0 1 2 1 0 9 8 7 6 3 4 5 6 5 4 3 } Complete Data Science Program(Live) public class Zprogram{ for(int j=0;j<=i;j++){ System.out.println(); import java.util.Scanner; Time complexity: O(h*w*w) for given height h and width w. This article is contributed by Nikhil Meherwal(S. Shafaq). else{ System.out.print(i); can anyone solve this 0 2 4 6 8 10 12 for(i=1;i<=10;i++) * 3 4 5 6 5 4 3 CHARACTER, Input Triangle ends: Pyramid numbers can be modelled in physical space with a given number of balls and a square frame that hold in place the number of balls forming the base, that is, n2. However, every row has leading white spaces whose count is rows-i. We are doing a letter pyramid using loops. The nature of simulating nature: A Q&A with IBM Quantum researcher Dr. Jamie We've added a "Necessary cookies only" option to the cookie consent popup. //Incrementing the rowCount This question tests the candidates logical ability as well as the basic understanding of Java language. 5 4 3 2 1 2 3 4 5 Engineering & Technology Computer Science Java Programming. Java Program to Print Pyramid Pattern Here is our Java program to draw the pyramid pattern as shown in the problem statement. Input. Example 2: Pyramid program in java to print full pyramid using the numbers. Polymorphism in Java Method Overloading and Overriding, What is the use of a Private Constructors in Java, How does Hashmap works internally in Java, Serialization and Deserialization in Java with Example. However, in this case there is no related array or List so sarting at 1 simplifies the logic. Enter a number: 10 You entered: 10. 2 1 for(k=2;k<=nextint;k++) Creating an X pattern with user input in Java? ******* To view the purposes they believe they have legitimate interest for, or to object to this data processing use the vendor list link below. We will also understand pyramid programs in java with the help of an example. Find centralized, trusted content and collaborate around the technologies you use most. System.out.print( +l); row++; 1 2 3 4 /*String printed = new String(new char[i]).replace("\0", i+" ");*/ int number = sc.nextInt(); Programs for printing pyramid patterns in Python, PHP programs for printing pyramid patterns, Programs for printing pyramid patterns in C++, Programs for Printing Pyramid Patterns using Recursion, Programs to print Triangle and Diamond patterns using recursion, Java Program to Print Pyramid Number Pattern, Java Program to Print Pyramid Star Pattern, Java Program to Print Reverse Pyramid Star Pattern, Design Patterns in Java - Iterator Pattern. The rowCount is initialized to nrows. 1 Plz code this program, /* * 15 18 21 7 8 9 10 1 2 Here, we have used the Java Scanner Class to take input from the user. Triangle number pattern programs In Java. * 2 * 4 * 6 1 2 4 8 16 32 64 128 64 32 16 8 4 2 1 { how to print this pattern, 1 12345 1234 123 12 1. . int n = input.nextInt(); Java Interviews can give a hard time to programmers, such is the severity of the process. System.out.print("* "); 1 * 5 6 7 8 9 0 9 8 7 6 5 *; public class PyramidPattern { public static void main (String args []) { int rows, i, space, star=0;; Scanner in = new Scanner (System.in); System.out.println ("Enter number of rows in pattern"); rows = in.nextInt (); Here is the code snippet for the inverted pyramid program. */ * * * * *, import java.lang. System.out.println(); System.out.println(); Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. 543212345 ************************* Java Program Solution How to print a Pyramid based on user input in java Printing a Pyramid based on user input.Source code is given below. }, /*. } Thank you very much! The symbol, character, and numbers are then printed based on the number of columns. 2 3 4 3 2 1 5 5 5 5 5 2 3 2 It then calls this method from the main method, which takes user input and outputs the generated message to the console. System.out.println(); while( middle <= input) Also I'm not sure how to format things in the comment reply box. public static void main(String args[]) * If you would like to change your settings or withdraw consent at any time, the link to do so is in our privacy policy accessible from our home page.. System.out.print(&); }, *########## 1000. 1 for(i=0; i<=n; i++){ In this article, we will learn what is pyramid program, how to create a half pyramid program in java, and a full pyramid program in java. } You got it almost right anyway as others pointed out. 6 5 4 3 2 1 2 3 4 5 6 In this tutorial, we will dicuss pyramid number pattern in Java using for loop System.out.print(/ ); 543212345 Java Code To Create Pyramid and Pattern In this program, you'll learn to create pyramid, half pyramid, inverted pyramid, Pascal's triangle and Floyd's triangle sing control statements in Java. 1 3 5 7 9 In the above code, the pyramid pattern is built using a nested for loops. **** bbbbbA And yes we have to duplicate the letter in the middle. 3.accept only numbers. } class empty_pyramid }, * 1 "After the incident", I started to be more careful not to trip over things. { 7 8 9 10 { To learn more, see our tips on writing great answers. 1 2 1 Enter the size of first array: 3. 24 27 class cls Example 3: Pyramid program in java to print half pyramid using alphabets. In this post, we will try to write the java programs to create pyramid of numbers inall different patterns. 0 2 4 6 * * * * * { In short, the value of j is decreased by 1 at every iteration thus the number of white spaces will reduce in every row. 3 2 4 Number of rows for the pyramid is accepted from the user. Pattern 4 : Write java program to print pyramid of numbers like in the Pattern4 of the above image? for col in range(1,row+1): if n= 7 **4321234** } And the result is displayed on the console using the main () method. ******* System.out.print(l); int n=Integer.parseInt(br.readLine()); Scanner sc = new Scanner(System.in); They can ask you to create pyramid of numbers withdifferent patternslike in the below image. else for(int i=1;i=1;j) } 5, how can we write this program *; public class GeeksForGeeks { public static void PyramidStar (int n) { { for(int k=1;k<=temp;k++) Im still trying to figure out the code to create a pattern 4 pyramid with prime numbers. Logic and write a program, import java.util. Example 11-Program to print inverted hollow star pyramid pattern In the following program, the user can enter a number of rows to print the inverted hollow star pyramid pattern as he wishes, then the result will be displayed on the screen: Code: ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING, We will send you an one time password on your mobile number, An OTP has been sent to your mobile number please verify it below. INPUT INTELLIGENCE PLUS CHARACTER IS EDUCATION 1 2 During each second inner for loop we will print one and after completion of the row, we will move to another row. import java.util.Scanner ; public class CodesCracker { public static void main (String [] args) { int num; Scanner s = new Scanner (System.in); System.out.print ( "Enter the Row Size of Pascal Triangle: " ); int row = s. nextInt (); for (int i=0; ii; space--) System.out.print ( " " ); num=1; for (int j=0; j<=i; j++) { System.out.print (num+ " " 1 2 3 * * * Example 1: Pyramid program in java to print full pyramid using the symbol *. I'm learning. They look almost impossible to crack at a point, but these questions are practically based on mathematical logic and matrices' fundamentals. 1 0 0 0 0 5 7 9 Please mail your requirement at [emailprotected] Duration: 1 week to 2 week. if(j%2==0){ } Here is just a variation that saves a loop Another solution using a single (explicit) loop: As mentioned elsewhere, loop variables such as i usually start at 0 since such variables can be used as an array/List index. of stars = Stars in Previous Row + 2. int nor=5,rowcount=1,i,j; 1 2 3 Simple pyramid pattern Java import java.io. * 2 * 4 int n=10; 1 7 2 6 3 5 4 4 5 3 6 2 7 1 The numbers in the series should be used to create a Pyramid. *; The value then used by for loop to print the pattern consisting user entered number of rows. for(j=1;j<=i;j++) Step 2: Then, We will take the value from the user to print the number of rows to print using Scanner and store it in the rows variable. 7 8 9 10, class program System.out.println(); ******* 7 30, how to print this, pls help me. for (int i = 0; i < totaldigit; i++) { System.out.print(m+" "); totaldigit = totaldigit + n; System.out.println(How Many Rows You Want In Your Pyramid?); 2 1 2 4. } You can print Pyramid pattern of stars or numbers using loops and print methods in Java. } 54321, can i get pattern like this In the above pyramid program in java, first, we will take the input from the user for the number of rows. 4 3 2 1 2 3 4 1 2 3 4 5 6, 5 4 3 2 1 * * { int n = S.nextInt(); 1 12 123 1234 12345, / / / / 1 / / / / System.out.println(" * "); 4 5 6 7 8 7 6 5 4 1.only even numbers should be printed; In the output, we can see that in the first line the value of i (1) is printed and the value of i increased by 1 in every upcoming row. }, how to print for (int j = 0; j <= i; j++) { what is the code? In this case, we can create a loop to iterate three times (3 weeks). The Java code for the above star pattern,if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'knowprogram_com-banner-1','ezslot_8',138,'0','0'])};__ez_fad_position('div-gpt-ad-knowprogram_com-banner-1-0');if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'knowprogram_com-banner-1','ezslot_9',138,'0','1'])};__ez_fad_position('div-gpt-ad-knowprogram_com-banner-1-0_1');.banner-1-multi-138{border:none!important;display:block!important;float:none!important;line-height:0;margin-bottom:7px!important;margin-left:auto!important;margin-right:auto!important;margin-top:7px!important;max-width:100%!important;min-height:250px;padding:0;text-align:center!important}. ****** 1. 9 0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 9 System.out.print(l++); C Program . * * * * *; no++; System.out.println(); It will print similar results. System.out.print("*"); { System.out.print(n++ +" "); The rowCount is initialized to 1. 32123 /* * * * * * int count=9; Exceptional, sustainable results. 4321234 patt.drawPatternExample(6); *** 3 //n3,2,1 left side of the pyramid Because you said you want to learn sth here's just an example. 4321234 { Take the input from the user and assign it to noOfRows. } int output = 0; * * There are two print method you need to know, System.out.print () and System.out.println (), the difference between print () and . In my example you avoid this by saving the half word instead of saving the whole word. Build a Java Class that asks a user to input a userid and password. The Java program for the above half pyramid star pattern is. } if(j%2==0) ; Inside the starPyramid() method, we have two nested for loops. } //first pyramid Learn Java practically In the output, we can see that in the first line one is printed and the number of * increased by 1 in every upcoming row. -********, help me to create this program please 4 5 6 System.out.print(j); Java is used to enforce the right side pattern. class Pat The pyramid star pattern in Java is one of them. 5 9 We have written the below print/draw Pyramid asterisk/star pattern program in four different ways with sample example and output, check it out. Step 3: We will write more than two for loops according to the pattern of the pyramid. Does it possible to draw the following pyramid without any loop? 7 8 9 0 1 2 3 4 3 2 1 0 9 8 7 2 4 All rights reserved. 1000000 int k=1; for(int j = Countrow+1; j<=n; j++){ After that, we will run an outer for loop from 1 to rows and we will run the first inner for loop from j=rows-1 to j>=1 where j is the current column number. The first for loop iterates the number of rows, while the second for loop iterates the number of columns. for (int j = 1; j <= i; j++) 1 3 3 1 System.out.print(" "); #include<stdio.h> int main() { int a[10],n,i; . Learn to code interactively with step-by-step guidance. In the above Java program, an input s is accepted from the user with the help of the Scanner class method. 1 4 6 4 1, 1 By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. class Pat 3 5 7 9 Previous: Write a program in Java to print such pattern like right angle triangle with number increased by 1. for(int j=0;j<=i;j++){ 212 Of course, no a series of a print statement. Here, user has to put the number or string as input to check if the number/string is palindrome. System.out.println(); //Printing 'rowCount' value 'rowCount' times at the end of each row // TODO Auto-generated method stub 65555555556 With the help of pyramidial number we can also print pyramid number pattern. count=num.nextInt(); * * } Int (j=0;j=1;i) Scanner input = new Scanner(System.in); } 1,4,6,4,1 }, for (int j = 1; j = 1; j) In the output, we can see that in the first line the value of j (1) is printed and the value of j increased by 1 in every upcoming row. *** Approach 1: Using a for loop Approach 2: Using a while loop Approach 3: To print the series up to a given number Approach 4: Using Recursive Function. * # * #, How to print ? 65433333456 { Pattern 1 : Write java program to create pyramid of numbers like in Pattern1of the above image? Reply. Why do many companies reject expired SSL certificates as bugs in bug bounties? { 1 2 1 Here is the code: import java.util. 5 4 3 2 1 2 3 4 5 In this program, we have two examples of printing pyramids, in the first, we have a printed pyramid of star characters, while, in the second example, we have drawn a pyramid of numbers. This article is created to cover a lot of pattern programs using star (*) in Java. }, Can you please provide prog for output Java Program to convert an integer into binary This C program is similar to pyramid star pattern, except here we are printing the rows in reverse order. Below is the java code which implements this logic. 67890109876 { Define one variable called rowCount and initialize it to 1. Java Full Course | Java Tutorial for Beginners | Java Online Training | Edureka In the output, we can see that in the first line one is printed and the number of * increased by 1 in every upcoming row. { System.out.println(); Step 3: We will write two for loops. 8 8 8 8 8 8 8 8 Full Stack Development with React & Node JS(Live) Java Backend Development(Live) React JS (Basic to Advanced) JavaScript Foundation; Machine Learning and Data Science. *****###### int noOfRows = sc.nextInt(); System.out.println(Here Is Your Pyramid); }. 1 1 Manage Settings for x in range(1,level+1): 0 2 4 6 8 } 0 2 4 6 8 10 An alphabet pattern program is a series of alphabets that generate a certain pattern or geometrical shapes like a square or triangle. } Java Pattern Programs have always been one of the critical parts of the Java Interview questions. System.out.println(Enter the number of rows: ); System.out.println(); DigitalOcean makes it simple to launch in the cloud and scale up as you grow whether youre running one virtual machine or ten thousand. In the above pyramid program in java, first, we will take the input from the user for the number of rows. 1 2 1 Continue with Recommended Cookies. System.out.print("\n"); 2 1 2 {. System.out.print(Enter your number : ); Take third/inner loop to print the column values. 2 4 1 C Program Asenthus Nyctophilia says: April 10, 2017 at 12:12 pm . int r=s.nextInt(); for (int i=1;i1;j) Does a summoned creature play immediately after being summoned by a ready action? } These patterns enhance your programming skills and are generated with the help of loops and if-else statements. 10 int row=1; System.out.print(k); public static void main(String[] args) { and Get Certified. Take the input from the user and assign it to noOfRows. To use the Scanner class, create an object of the class and use any of the available methods found in the Scanner class documentation. if(i!=0) Thank you for helping. 1 2 3 We will try to keep the code simple so that it can be easily understood. * 3 4 5 6 5 4 3 * * { Number of rows for the pyramid is accepted from the user. 3 4 5 6 5 4 3 This program uses the Scanner class to take input from the command prompt and nested loop to print the pyramid pattern of alphabets. { }, public static void main(String []args){ } { } How To Install Grails on an Ubuntu 12.04 VPS, Simple and reliable cloud website hosting, New! System.out.print("*"); Thanks for learning with the DigitalOcean Community. I apologize. please help me out with this program, public class MainClass 1, how can you get output like this. * & * & * & i.e in the first row, 1 will be printed once. To learn more, see our tips on writing great answers. To create this kind of pattern generally, we have to use two for loops. This article is aimed at giving a Java implementation for pattern printing. Not the answer you're looking for? Is below are possible to write a code in java? 8 9 0 1 2 3 4 5 6 5 4 3 2 1 0 9 8