java program to print the following series 1.5,3.0,4.5,6.0,....
Answers
Answered by
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:
- Initialise a variable 'a' with the value 1.5
- Ask the user to enter the limit (n).
- Iterate a loop n times.
- Display the value of a with a space. Increment the value of a by 1.5
See the attachment for output ☑.
Attachments:
Answered by
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