Saturday, February 6, 2016

Program to take the marks of N number of students & do the operations.

/*WAP to take the marks of N number of students.
Display the marks of all the students.
Display the marks of students whose marks are more than or equal to 39.
Display the marks of students whose marks are less than  39.
Display the marks of students whose marks are more than or equal to average marks.
*/

import java.util.*;
public class score
{
public static void main(String []args)
{
Scanner in=new Scanner(System.in);
double marks[]=new double[100];
double sum=0.0, avg;
int n, c;
char ch='y';
//For taking the number of students.
System.out.print("Enter the No. of Students : ");
n=in.nextInt();

//For taking the marks of the no. of students.
for(int i=0;i<n;i++)
{
marks[i]=(int)(Math.random()*100);
sum=sum+marks[i];
}
avg=(int)(sum/n);

do
{
System.out.println("\n\nFollowing Operations can be done.");
System.out.println("1. Show Marks of all students.");
System.out.println("2. Show Marks of students whose marks are more than equal 39.");
System.out.println("3. List of students whose marks are less than 39.");
System.out.println("4. List of students whose marks are more than or equal to average.");
System.out.print("   Enter Your Choice : ");
c=in.nextInt();
switch(c)
{
case 1:
//Displaying the marks obtained by the no. of students.
for(int i=0;i<n;i++)
{
System.out.println("Roll No. "+(i+1)+" : "+marks[i]);
}
break;

case 2:
//Displaying the list of students whose marks are more than 39
for(int i=0;i<n;i++)
{
if(marks[i]>=39)
System.out.println("Roll No. "+(i+1)+" : "+marks[i]);
}
break;

case 3:
//Displaying the list of students whose marks are more than 39
for(int i=0;i<n;i++)
{
if(marks[i]<39)
System.out.println("Roll No. "+(i+1)+" : "+marks[i]);
}
break;

case 4:
System.out.println("The Average marks of the student is : "+avg);
//Displaying the list of students whose marks are more than or equal to average marks
for(int i=0;i<n;i++)
{
if(marks[i]>=avg)
System.out.println("Roll No. "+(i+1)+" : "+marks[i]);
}
break;

default:
System.out.println("Please enter the correct option.");
break;
}

System.out.print("\n\nDo you want to run the options again (Y/N) ? ");
String str=in.next();
ch=str.charAt(0);

}while(ch=='y'||ch=='Y');
}
}

Wednesday, January 13, 2016

Pattern-45

/**
Pattern-45:
Enter N : 5
    5
   5 4
  5 4 3
 5 4 3 2
5 4 3 2 1
*/

import java.io.*;

public class Pattern45
{
 public static void main(String args[])throws IOException
 {
     int i, j, k, n;
     InputStreamReader read = new InputStreamReader(System.in);
     BufferedReader in = new BufferedReader(read);

     System.out.print("Enter N : ");
     n=Integer.parseInt(in.readLine());

     for(i=n;i>=1;i--)
     {
         for(j=1;j<i;j++)
         {
             System.out.print(" ");
         }
         for(k=n;k>=i;k--)
         {
             System.out.print(k+" ");
         }
         System.out.println();
     }
 }
}

Pattern-44

/**
Pattern-44:
Enter N : 5
    1
   1 2
  1 2 3
 1 2 3 4
1 2 3 4 5
*/

import java.io.*;

public class Pattern44
{
 public static void main(String args[])throws IOException
 {
     int i, j, k, n;
     InputStreamReader read = new InputStreamReader(System.in);
     BufferedReader in = new BufferedReader(read);

     System.out.print("Enter N : ");
     n=Integer.parseInt(in.readLine());

     for(i=1;i<=n;i++)
     {
         for(j=1;j<=n-i;j++)
         {
             System.out.print(" ");
         }
         for(k=1;k<=i;k++)
         {
             System.out.print(k+" ");
         }
         System.out.println();
     }
 }
}

Pattern-43

/**
Pattern-43:
Enter N : 5
    5
   4 4
  3 3 3
 2 2 2 2
1 1 1 1 1
*/

import java.io.*;

public class Pattern43
{
 public static void main(String args[])throws IOException
 {
     int i, j, k, n;
     InputStreamReader read = new InputStreamReader(System.in);
     BufferedReader in = new BufferedReader(read);

     System.out.print("Enter N : ");
     n=Integer.parseInt(in.readLine());

     for(i=1;i<=n;i++)
     {
         for(j=1;j<=n-i;j++)
         {
             System.out.print(" ");
         }
         for(k=1;k<=i;k++)
         {
             System.out.print((n-i+1)+" ");
         }
         System.out.println();
     }
 }
}

Wednesday, January 6, 2016

Pattern-42

/**
Pattern-42:
Enter N : 5
    1
   2 2
  3 3 3
 4 4 4 4
5 5 5 5 5

*/

import java.io.*;

public class Pattern42
{
 public static void main(String args[])throws IOException
 {
     int i, j, k, n;
     InputStreamReader read = new InputStreamReader(System.in);
     BufferedReader in = new BufferedReader(read);

     System.out.print("Enter N : ");
     n=Integer.parseInt(in.readLine());

     for(i=1;i<=n;i++)
     {
         for(j=1;j<=n-i;j++)
         {
             System.out.print(" ");
         }
         for(k=1;k<=i;k++)
         {
             System.out.print(i+" ");
         }
         System.out.println();
     }
 }
}

Pattern-41

/**
Pattern-41:
Enter N : 5
    &
   & &
  & & &
 & & & &
& & & & &

*/

import java.io.*;

public class Pattern41
{
 public static void main(String args[])throws IOException
 {
     int i, j, k, n;
     InputStreamReader read = new InputStreamReader(System.in);
     BufferedReader in = new BufferedReader(read);

     System.out.print("Enter N : ");
     n=Integer.parseInt(in.readLine());

     for(i=1;i<=n;i++)
     {
         for(j=1;j<=n-i;j++)
         {
             System.out.print(" ");
         }
         for(k=1;k<=i;k++)
         {
             System.out.print("& ");
         }
         System.out.println();
     }
 }
}