I don\'t understand what I\'m doing wrong. As of right now I\'m trying the grasp
ID: 3545081 • Letter: I
Question
I don't understand what I'm doing wrong. As of right now I'm trying the grasp the concept of arrays, can someone please help me
I've been at these two problems for almost 3 hrs now.
1. Write the code to fill successive elements of an array with values 5, 7, 9, 11, ... 225. Do not use a READ statement. Also I have to start at A[0] and my instructor wants me to add 225-5/2 + 1. "She's always changing our problems."
2. Assume array A with 50 elements has already been loaded. Write the code to compare the sum of the squares of the elements of the array A. I have to start at A[1]
Explanation / Answer
Part 1
import java.util.*;
import java.io.*;
class Mukesh
{
public static void main(String args[])
{
int size=((225-5)/2) +1;
int A[]=new int[size];
A[0]=5;
for(int i=1;i<size;i++ )
{
A[i]=A[i-1]+2; // Next value of array is sum of previous and 2, it is to make odd entries
}
for(int i=0;i<size;i++ )
{
System.out.print(A[i]+" ");
}
}
}
Part 2
Your second question is not clear, I did not get what do you want to compare.
So, I just print the square of array entries,
If you want something else, or modifications, let me know, I will help you.
And one more thing regarding your comment, there are some spam comments and email ids, just ignore them
import java.util.*;
import java.io.*;
class Mukesh
{
public static void main(String args[])
{
int A[]=new int[50];
for(int i=1;i<50;i++ )
{
A[i]=i;
}
for(int i=0;i<50;i++ )
{
System.out.print(A[i]*A[i]+" ");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.