1.Modify your program by enclosing your loop in another loop so that you can fin
ID: 3570502 • Letter: 1
Question
1.Modify your program by enclosing your loop in another loop so that you can find consecutive sums. For example , if 5 is entered, you will find five sum of consecutive numbers:
1 = 1
1+2 = 3
1+2+3 =6
1+2+3+4 =10
1+2+3+4+5 =15
Print only each sum, not the arithmetic expression
2. Decision Structures and Boolean Logic
1. Write an if statement that assigns 20 to the variable y and assigns 40 to the variable z if the variable x is greater than 100.
2. Write an if statement that assigns 0 to the variable b and assigns 1 to the variable c if the variable a is less than 10.
3. Write an if-else statement that assigns 0 to the variable b if the variable a is less than 10.
Otherwise, it should assign 99 to the variable b.
Explanation / Answer
1.) import java.io.*;
class Sum
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your number:");
int input=Integer.parseInt(br.readLine());
int sum=0,i=0,j=0;
for(i=1;i<=input;i++)
{
sum=0;
for(j=1;j<=i;j++)
{
sum=sum+j;
}
System.out.println(j);
}
}
}
2.) 1.) if(x>100)
{
y=20;
z=40;
}
2.) if(a<10)
{
b=0;
c=1;
}
3.) if(a<10)
b=0;
else
b=99;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.