RECENTLY MOST VIEWS
-
import java.util.HashSet; class DuplicateNumberArray { public static void main(String[] args) { int[] arr={1,2,3,1,10,20,30,20,1};...
-
Note:- To search an element in an array elements must be sorted before search otherwise we will get unpredictable result. because java.u...
-
import java.io.Console; class ReverseString { public static void main(String[] args) { Console c=System.console(); String s=c.r...
-
import static java.lang.System.out; import java.util.Arrays; class SortArray2 { static public void main(String...alt) { String[...
-
Write a program in java to find the longest palindrome from the given String. If the length is same then print in descending order. Inp...
-
import java.util.HashSet; class DuplicateNumberArray2 { public static void main(String[] args) { String[] arr = {"xy...
-
Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or not. ...
-
For example, If given number 165 a nd given digit is 6 then you should find the largest number less than 165 but it should not contain ...
MOST POPULAR
-
Note: A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number. For e...
-
The International Mobile Station Equipment Identity(IMEI) is a number, usually unique, to identify mobile phones, as well as some satellit...
-
For example, If given number 165 a nd given digit is 6 then you should find the largest number less than 165 but it should not contain ...
-
Write a Java program to take an string array and find the duplicate and sort in ascending order. import java.util.*; class RemoveDupl...
-
/* Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or no...
Blog Archive
-
▼
2018
(38)
-
▼
August
(19)
- How to convert string into int primitive data type?
- Write a JAVA program for the given string and take...
- How to find largest number less than a given numbe...
- How to count occurrences of each character of a st...
- How to count occurrences of each character of a st...
- How to find second largest number in an integer ar...
- How to find sum of all digits of a number in java?
- How to find duplicate elements in an array using H...
- How to find duplicate elements in an array?
- Java Program to check two strings are Anagram or not
- How do you check the equality of two inner arrays ...
- How do you check the equality of two arrays in java?
- How to count duplicate characters in a string in j...
- How to find duplicate characters in a string in java?
- How do you remove all white spaces from a string i...
- How do you remove all white spaces from a string i...
- How to print Number Pyramid Pattern in java?
- How to create a pyramid of numbers in java?
- How to reverse a string in java?
-
▼
August
(19)
About
Hello ALTAF
Showing posts with label number-pyramid-pattern. Show all posts
Showing posts with label number-pyramid-pattern. Show all posts
Sunday, August 19, 2018
Thursday, August 16, 2018
How to create a pyramid of numbers in java?
package com.npp.test;
public class Test {
public static void main(String[] args) {
int n=10;
for(int i=1;i<=n;i++)
for(int j=1;j<=n+1;j++)
System.out.print(i>9?j<=n-i+1?" ":i+" ":j<=n-i+1?" ":i+" ");
}
System.out.println();
}
Instead of writing ternery operator we can write this also
if(i>9)
System.out.print(j<=n-i+1?" ":i+" ");
else
System.out.print(j<=n-i+1?" ":i+" ");
Subscribe to:
Posts (Atom)
Program List
- armstrong
- char-occurrances
- check-anagram
- check-duck-no
- check-duplicate-no
- check-endianess-of-os
- check-equality-of-two-arrays
- check-fibonacci-series
- check-harshad-no
- check-kaprekar
- check-keith-no
- check-niven-no
- check-palindrome
- check-prime
- check-prime-no
- check-substring
- check-unique-no
- check-valid-imei
- convert-array-to-list
- convert-string-to-int
- count-duplicate-char-in-string
- count-occurrences-char-of-string
- create-immutable-class
- disarium
- filter-number
- find-1st-non-repeat-char
- find-common-no-in-array
- find-duplicate-char-in-string
- find-duplicate-no-in-array
- find-largest-no-less-than-given-no
- find-palindrome
- find-second-largest-number
- image-store-in-database
- jdbc-program
- number-pyramid-pattern
- numeric-pattern
- remove-duplicate-in-string-array
- remove-white-space-of-string
- reverse-list
- reverse-string
- search-element-in-array
- search-list
- sorting-array
- sorting-list
- sorting-user-defined-object
- string-reverse
- sum-of-all-digits
- swap-2-no
- view-system-properties