Computer Science, asked by gamingpro539, 3 months ago

java program to print the following series 1.5,3.0,4.5,6.0,....

Answers

Answered by anindyaadhikari13
3

Required Answer:-

Question:

  • Write a Java program to display the series - 1.5, 3.0, 4.5 . . . . . N terms.

Solution:

Here comes the program.

import java.util.*;

public class Java {

 public static void main(String[] args) {

    Scanner sc=new Scanner(System.in);

    int n, i;

    double a=1.5;

    System.out.print("Enter limit: ");

    n=sc.nextInt();

    for(i=1;i<=n;i++,a+=1.5)

       System.out.print(a+" ");

    sc.close();

 }

}

Logic To Solve:

  1. Initialise a variable 'a' with the value 1.5
  2. Ask the user to enter the limit (n).
  3. Iterate a loop n times.
  4. Display the value of a with a space. Increment the value of a by 1.5

See the attachment for output .

Attachments:
Answered by harsidkhan456
0

Answer:

we hane to add 7.5+15

Explanation:

1.5+1.5=3.0

3.0+1.5=4.5

4.5+1.5=6.0

6.0+1.5=7.5

7.5+1.5=9.0

Similar questions