QuestionAsk Questions?

View Answers

March 16, 2009 at 11:42 PM

Hi Friend,

We are providing you some code according to your examples. Please try them in solving your problems.

// Answer 7

public class Answer7 {

public static void main(String artgs[]) {

int i, j, k;

for (i = 1; i <= 10; i++) {

for (j = 1; j <= i; j++) {

System.out.print((i + j - 1) % 10);

}

for (k = (i + j - 2); k > i; k--) {

System.out.print((k-1)%10);

}

System.out.println();

}

}

}

// Answer 8

public class Answer8 {

public static void main(String artgs[]) {

for (int i = 1; i <= 9; i++) {

for (int j = 1; j <= i; j++) {

System.out.print(j);

}

for (int k = i - 1; k >= 1; k--) {

System.out.print(k);

}

System.out.println();

}

}

}

// Answer 9

public class Answer9 {

public static void main(String args[]) {

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5 - i; j++) {

System.out.print(Character.toChars(90 - j));

}

for (int k = 4 - i; k > 0; k--) {

System.out.print(Character.toChars(90 - k + 1));

}

System.out.println();

}

}

}

//Answer 11

import java.io.*;

import java.math.*;

public class Answer11 {

public static void main(String args[]) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the the value of x : ");

String x = br.readLine();

System.out.println("Enter the the value of n : ");

int n = Integer.parseInt(br.readLine());

long sum = 0;

for (int i = 1; i <= n; i++) {

sum = sum + new BigInteger(x).pow(i).intValue();

}

System.out.println(sum);

}

}

Thanks for posting questions.

RoseIndia Team

We are providing you some code according to your examples. Please try them in solving your problems.

// Answer 7

public class Answer7 {

public static void main(String artgs[]) {

int i, j, k;

for (i = 1; i <= 10; i++) {

for (j = 1; j <= i; j++) {

System.out.print((i + j - 1) % 10);

}

for (k = (i + j - 2); k > i; k--) {

System.out.print((k-1)%10);

}

System.out.println();

}

}

}

// Answer 8

public class Answer8 {

public static void main(String artgs[]) {

for (int i = 1; i <= 9; i++) {

for (int j = 1; j <= i; j++) {

System.out.print(j);

}

for (int k = i - 1; k >= 1; k--) {

System.out.print(k);

}

System.out.println();

}

}

}

// Answer 9

public class Answer9 {

public static void main(String args[]) {

for (int i = 0; i < 5; i++) {

for (int j = 0; j < 5 - i; j++) {

System.out.print(Character.toChars(90 - j));

}

for (int k = 4 - i; k > 0; k--) {

System.out.print(Character.toChars(90 - k + 1));

}

System.out.println();

}

}

}

//Answer 11

import java.io.*;

import java.math.*;

public class Answer11 {

public static void main(String args[]) throws Exception {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the the value of x : ");

String x = br.readLine();

System.out.println("Enter the the value of n : ");

int n = Integer.parseInt(br.readLine());

long sum = 0;

for (int i = 1; i <= n; i++) {

sum = sum + new BigInteger(x).pow(i).intValue();

}

System.out.println(sum);

}

}

Thanks for posting questions.

RoseIndia Team

Related Tutorials/Questions & Answers: