Some Java programs part-5

21. Write a program that will calculate the value of Z  if the expression of y is as follows (n is the input):

Series 21

/* Time: 12:28am
 * Author : Anik Das*/
import java.util.Scanner;
public class Faraz21{
  public static void main ( String [] args ){
    int a = 1, c=1, n = 0;
    double z = 0;
    double sum1=0.0, sum2=0.0;
    Scanner input = new Scanner ( System.in );
    System.out.println("Enter Value OF n");
    n = input.nextInt();
    while (c<=n){
      if (c%2!=0){
        sum1 = sum1 + Math.pow(c,2);
      }else{
        sum2 = sum2 - Math.pow(c,2);
      }
      c++;
    }
    int sum = (int) (sum1+sum2);
    z = Math.pow(sum,3);
    System.out.println("Value Of Z is"+z);
  }
}

22. Write a program that will calculate the value of y if the expression of y is as follows (n is the input):

/*Time : 7.37am
 * Author: Anik Das*/
import java.util.Scanner;
public class Faraz22{
  public static void main ( String [] args ){
  double n = 0, c = 1, sum = 0;
  Scanner input = new Scanner ( System.in );
  System.out.println("Enter The Value Of N :");
  n = input.nextDouble();
  while (c<=n){
    sum = sum + (c/(2*c - 1));
    c++;
  }
  System.out.println("The Value Of Y is : "+sum);
  }
}

23. Write a program, which adds all the multiples of 7 and 9 up to 300. 24. .  An integer number is said to be a perfect number if its factors, including 1 but not the number itself, sum to the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3. Write a complete flowchart of a program, which finds and prints all perfect numbers that are less than 1600.

/* Time: 10:30 am
 * Author : Anik Das*/
public class Faraz23{
  public static void main ( String [] args ){
    int sum=0, c = 1 ;
    while ( c<=300 ){
      if ((c%7==0)||(c%9==0)){
        sum = sum + c;
      }
      c++;
    }
    System.out.println("Sum Is : "+sum);
  }
}

25. Write a program that finds and displays all the prime numbers less than 1000.

/* Time : 10:53 am
 * Author : Anik Das */
public class Faraz25{
  public static void main ( String [] args ){
    int c = 1, sum = 0;
    while (c<=11){
      int n=1, k=0;
      while (n<=c){
        if(c%n==0){
        k=k+1;
        }
        n++;
      }
      if (k==2){
        sum = sum + c;
        System.out.println("Perfect Number : "+c);
      }
      c++;
    }
    System.out.println("Sum : "+sum);
  }
}

About anik

This is Anik Das. I am Student of Electrical and Electronics engineering in National Institute of Technology, Warangal (NITW). I used to study in BRAC University(BRACU) (which is one of the best part of my life). There I also studied EEE but after getting the ICCR Scholarship by the Indian Govt. I moved to NITW. I have completed my H.S.C from Notre Dame College (NDC). I used to work as Microsoft Student Partner(MSP) in Microsoft. I am a tech loving boy…I also love to know about newer and newer things. I am here to share what I learn...

Posted on April 4, 2011, in java, java program, simple java progams and tagged , , , , , . Bookmark the permalink. 2 Comments.

  1. nice ! Liked! Keep it up.
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: