This is the program for printing the numbers in the below format:
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15
Method 1:
public void printFormat2(){
int nCount = 1, rowCount = 10;
for (int i = 1; i <= rowCount; i++) {
int temp = 0;
if (i == 2) {
temp = nCount + 1;
} else {
temp = nCount + i - 1;
}
for (int j = 1; j <= i; j++) {
if (i % 2 == 0) {
System.out.print(temp);
temp--;
} else {
System.out.print(nCount);
}
if (i != 1 && j != i) {
System.out.print("*");
}
nCount++;
}
System.out.println("");
}
}
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15
Method 1:
public void printFormat1(){
int num = 10;
for(int i = 1; i <= num; i++){
System.out.println(formString("",getStartNum(i),i,(i%2 == 0 ? -1 : 1)));
}
}
public int getStartNum(int num){
int incrRdecr = num%2 == 0 ? -1 : 1;
int sum = (num * (num+1))/2;
if(incrRdecr == 1){
return sum - num + 1;
}else{
return sum;
}
}
public String formString(String str, int startNum,
int countNum, int incrCount){
String resp;
if(countNum == 0){
str = (str + startNum);
resp = str.substring(0, str.lastIndexOf("*"));
return resp;
}else{
resp = formString(str + startNum + "*",(startNum + incrCount),--countNum, incrCount);
return resp;
}
}
Method 2:
public void printFormat2(){
int nCount = 1, rowCount = 10;
for (int i = 1; i <= rowCount; i++) {
int temp = 0;
if (i == 2) {
temp = nCount + 1;
} else {
temp = nCount + i - 1;
}
for (int j = 1; j <= i; j++) {
if (i % 2 == 0) {
System.out.print(temp);
temp--;
} else {
System.out.print(nCount);
}
if (i != 1 && j != i) {
System.out.print("*");
}
nCount++;
}
System.out.println("");
}
}
buy-lsd-sheets-online/
ReplyDeletebuy-mountain-man-cake/
buy-honey-nut-bar-online/
buy-good-day-sunshine-online/
buy-merciful-brownie-online/
buy-cannabis-caramel-corn/
buy-mountain-man-espresso-cookie/
buy-peanut-butter-mm-cookie/
buy-moroc-caramello-online/
buy-moroccan-primero-hash/
buy-afghan-black-hash/
buy-bubble-hash-online-virginia/
buy-charas-hash-online-kentucky/
buy-honey-morocan-blonde-hash/
big-chief-carts/
order-ufo-carts-online/
buy-narcotics-online/
raw-garden-carts/
ReplyDeletebuy-sweet-tea-weed-strain-online/
buy-sticky-buns-kush-online/
buy-pomelo-kush-online-ohio/
buy-pink-rozay-kush-online/
buy-ocean-beach-kush/
buy-london-chello-kush-online/
buy-honey-bun-kush/
buy-collins-ave-online/
buy-london-pound-cake-75-online/
buy-snow-man-online/
buy-gelato-strain-online/
buy-grand-daddy-purple-online/
buy-gary-payton-cookies-online/
buy-grenadine-online/
buy-cereal-milk-online/
buy-pancakes-online/
buy-blue-dream-online/
buy-amnesia-haze-online/
buy-northern-lights-online/