Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
MCS 182 - ( 2009-2010 Spring ) – LAB 3 Answers
Program 5)
import java.util.Scanner;
public class Program5 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter The Length: ");
int length=input.nextInt();
for (int i=0; i<length; i++){
for (int k=1; k<length-i; k++){
System.out.print(" ");
}
for (int k=0; k<i; k++){
System.out.print("*");
}
System.out.println();
}
}}
Program 6)
1st way:
import java.util.Scanner;
public class A{
public static void main(String[] args){
Scanner b= new Scanner(System.in);
System.out.println("Enter the dimension");
int dim =b.nextInt();
for(int j=dim-1; j>=0;j--){
for(int k=1;k<dim-j;k++){
System.out.print("*");
}
for(int k=0; k<j; k++){
System.out.print(" ");
}
System.out.println();
}
}
}
2nd way:
import java.util.Scanner;
public class gen{
public static void main (String [] args){
Scanner input= new Scanner (System.in);
System.out.print("Enter the dimension:");
int dim = input.nextInt();
for(int j=0;j<dim ;j++ ){
for(int k=1;k<dim - (dim*j) ; k++ ){
System.out.print(" ");
}
for (int k =0; k<j; k++){
System.out.print("*");
}
System.out.println();
}
}
}
Program 7)
import java.util.Scanner;
public class Program6 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i,n;
long f=1;
System.out.print("Enter The Number: ");
n=input.nextInt();
for (i=1; i<=n ; i++)
f=f*i;
System.out.printf("The Factorial is %d \n",f);
}}
Program 8)
import java.util.Scanner;
public class Program7 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int i,n;
long f;
n=1;
while (n!=0) {
System.out.print("\n Enter The Number: ");
n=input.nextInt();
f=1;
for (i=1; i<=n ; i++)
f=f*i;
System.out.printf("The Factorial is %d ",f);
}} }