Archive

Archive for January 6, 2009

Java Program to create star triangle pattern – Q12

January 6, 2009 Leave a comment

Q12: Java Program to create star triangle pattern

class star_triangle{
	public static void main(String args[]){
		int i, j, k;
		for(i=0; i<10; i++){
			for(j=i; j<10; j++){
				System.out.print(" ");
			}
			for(k=0; k<i;  k++){
				System.out.print(" " + "*");
			}
			System.out.println();
		}
	}
}

… from College notes (BCA/MCA assignments):


Categories: Java Tags:

Java Program to find Armstrong number (sum of cubes of individual digits is equal to the given number) – Q11

January 6, 2009 Leave a comment

Q11: Java Program to find Armstrong number (sum of cubes of individual digits is equal to the given number)

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself.

For example: 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.

class armg{
	public static void main(String args[]){
		int num;
		num = Integer.parseInt(args[0]);
		int res=0, x, n;
		while(num != 0){
			x = num % 10;
			res += x*x*x;
			num /= 10;
			}
		n = Integer.parseInt(args[0]);
		if(n == res)
			System.out.println(args[0] + " is Armgstrong Number");
		else
			System.out.println(args[0] + " is not Armgstrong Number");
	}
}

… from College notes (BCA/MCA assignments):