f_boboy
May 30th, 2001, 08:56 AM
Hi, I have a problem with my array program
My code:
import java.io.*;
import java.text.*;
public class Q1a
{
public static void main (String[] args) throws IOException
{
int numb1;
int tempsum;
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
System.out.print("How many numbers will you enter?");
numb1 = Integer.parseInt(stdin.readLine());
System.out.println ("Enter " + numb1 + " integers one per line:");
int [] list = new int[numb1];
for(int index=0; index < list.length; index++)
{
System.out.flush();
list[index]=Integer.parseInt(stdin.readLine());
}
tempsum = sumArray(list);
System.out.println ("The Sum is " + tempsum);
for(int index=0; index < list.length;index++)
{
System.out.flush();
System.out.println ((list[index] + percentage(list[index],tempsum)) + "% of the sum.");
}
}
}
public int sumArray(int[] temp1)
{
int sum=0;
for(int index=0; index < temp1.length; index++)
{
sum = temp1[index] + sum;
}
return sum;
}
public float percentage(float a, float b)
{
float c=0.0f;
float x,y
x = a;
y = b;
c = (x/y) * 100;
return c;
}
The error:
35:Identifier expected.
public int sumArray(int[] temp1)
^
35: 'class' or 'interface' keyword expected.
public int sumArray(int[] temp1)
^
24: Method sumArray(int[]) not found in class Q1a.
tempsum = sumArray(list);
^
30: Method percentage(int, int) not found in class Q1a.
System.out.println ((list[index] + percentage(list[index],tempsum)) + "% of the sum.");
Can anybody help me whats wrong with my code, thanx
My code:
import java.io.*;
import java.text.*;
public class Q1a
{
public static void main (String[] args) throws IOException
{
int numb1;
int tempsum;
BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
System.out.print("How many numbers will you enter?");
numb1 = Integer.parseInt(stdin.readLine());
System.out.println ("Enter " + numb1 + " integers one per line:");
int [] list = new int[numb1];
for(int index=0; index < list.length; index++)
{
System.out.flush();
list[index]=Integer.parseInt(stdin.readLine());
}
tempsum = sumArray(list);
System.out.println ("The Sum is " + tempsum);
for(int index=0; index < list.length;index++)
{
System.out.flush();
System.out.println ((list[index] + percentage(list[index],tempsum)) + "% of the sum.");
}
}
}
public int sumArray(int[] temp1)
{
int sum=0;
for(int index=0; index < temp1.length; index++)
{
sum = temp1[index] + sum;
}
return sum;
}
public float percentage(float a, float b)
{
float c=0.0f;
float x,y
x = a;
y = b;
c = (x/y) * 100;
return c;
}
The error:
35:Identifier expected.
public int sumArray(int[] temp1)
^
35: 'class' or 'interface' keyword expected.
public int sumArray(int[] temp1)
^
24: Method sumArray(int[]) not found in class Q1a.
tempsum = sumArray(list);
^
30: Method percentage(int, int) not found in class Q1a.
System.out.println ((list[index] + percentage(list[index],tempsum)) + "% of the sum.");
Can anybody help me whats wrong with my code, thanx