can some1 help me wid diz?!

import java.io.*;

public class looping1{
	public static void main(String args[])throws Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader (System.in));
		
		int value = 1;
	
		
			
		for (int i = 1; i<=11;i++ ){
			System.out.println(value);
			
			value = i + value;}
			
					

	
}}

the output should be:
1
2
4
7
11
16
32
39
47
56
66

Recommended Answers

All 7 Replies

can some1 help me wid diz?!

import java.io.*;

public class looping1{
	public static void main(String args[])throws Exception{
		
		BufferedReader br = new BufferedReader(new InputStreamReader (System.in));
		
		int value = 1;
	
		
			
		for (int i = 1; i<=11;i++ ){
			System.out.println(value);
			
			value = i + value;}
			
					

	
}}

the output should be:
1
2
4
7
11
16
32
39
47
56
66

Why do you have a BufferedReader? Do you need input from the user? If so, display a prompt so they know what to type in. If not, remove the BufferedReader. It may not cause any problems, but if you don't need it, then don't have it. You mention what the desired output is. What is the ACTUAL output?

What help do you need? If it's not working properly, tell us what's wrong with the output. If it gives an error message, tell us what it is.

Why do you have a BufferedReader? Do you need input from the user? If so, display a prompt so they know what to type in. If not, remove the BufferedReader. It may not cause any problems, but if you don't need it, then don't have it. You mention what the desired output is. What is the ACTUAL output?

the output of the one i made is this:
1
2
4
7
11
16
22
29
37
46
56


but the actual output should be diz:
1
2
4
7
11
16
32
39
47
56
66

it should skip 22 after 16 and direct to 32..

What help do you need? If it's not working properly, tell us what's wrong with the output. If it gives an error message, tell us what it is.

the output of the one i made is this:
1
2
4
7
11
16
22
29
37
46
56


but the actual output should be diz:
1
2
4
7
11
16
32
39
47
56
66

it should skip 22 after 16 and direct to 32..


but the actual output should be diz:
1
2
4
7
11
16
32
39
47
56
66

it should skip 22 after 16 and direct to 32..

What's the pattern? What mathematical series creates this? I don't see one off the top of my head.

add +10 to the value when the value hits 22 (22 +10 = 32) and let the loop just go after that... then u got your pattern... If I understood this correct

cheers!

As I understand it, yur program is adding 1+2+3+4..... and printing the sum at each stage. In which case, your program is correct.
...
7+4 = 11
11+5 = 16
16+6 = 22
22+7 = 29
29+8 = 37

You should not see 32, 39,47. You expected results are wrong, not the program!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.