Computer Science, asked by sunitamahawar92, 9 months ago

7. Write a program in java that produces the following output when n = 4.

Attachments:

Answers

Answered by expertgenius1st
0

Answer:

Question1. What will be the output of the following programs? Give reasons. [4, 7, 4] No credit will be given if you do not give reasons (even if your output is correct). Also, if the reasoning is wrong then you will not get any credit for just writing the correct output. class q1a{    public static void sumUp(int n, int total){       int i;       for (i=1; i<=n; i++){          total = total +i;       }    }    public static void main(String args[]){       int n, total;       n=10; //n can be initialized to any +ve number       total=0;       sumUp(n, total);       System.out.println(total);    } }

Question1. What will be the output of the following programs? Give reasons. [4, 7, 4] No credit will be given if you do not give reasons (even if your output is correct). Also, if the reasoning is wrong then you will not get any credit for just writing the correct output. class q1a{    public static void sumUp(int n, int total){       int i;       for (i=1; i<=n; i++){          total = total +i;       }    }    public static void main(String args[]){       int n, total;       n=10; //n can be initialized to any +ve number       total=0;       sumUp(n, total);       System.out.println(total);    } } class point{    int p,q;    point(int p, int q){       this.p=p; this.q=q;    }    void printpoint(){       System.out.println(this.p+" "+this.q);    } } class q1b{    public static void origin1(point p){       p = new point(0,0);    }    public static void origin2(point p){       p.p=15;       p.q=20;    }    public static void main(String args[]){       point q = new point(10,66);       origin1(q);       q.printpoint();       origin2(q);       q.printpoint();    } }

Similar questions