I am a learner just now.And I am trying problem "609A" in java. there is an error "_Runtime error:exit code is 1_" at the time of submitting the code. Please help me with this code.
and code is -:
//609A-USB selection for given memory size//
import java.util.Scanner;
class data
{
int n,s,m=0,i;
int[] a = new int[n];
void data()
{
Scanner in = new Scanner(System.in);
System.out.println("\n");
//System.out.println("enter number of drives and size of file :");
n = in.nextInt();
s = in.nextInt();
//System.out.println("n & s ="+n+" "+s);
int[] b = new int[n];
for (i=0;i<n;i++)
{
b[i] = in.nextInt();
}
a = b;
}
}
public class usb
{
public static void main()
{
int c=0,temp = 0,sum = 0;
data da = new data();
da.data();
for(int i= 0; i<da.n;i++) //0 to length of a.
{
for(int j=i; j<da.n;j++) //from i to length.a;
{
if(da.a[i]<da.a[j])
{
da.a[i] = da.a[i]+da.a[j];
da.a[j] = da.a[i]-da.a[j];
da.a[i] = da.a[i]-da.a[j];
}
}
}
int f=0;
for(int i= 0; i<da.n;i++)
{
if(f==0)
{
sum=0;
c=0;
}
for(int j=i;j<da.n;j++)
{
temp = da.a[j];
sum = sum + temp;
if(temp == da.s)
{
c=1;
f=1;
break;
}else
if(f==0)
{
if(sum == da.s)
{
c++;
f=1;
break;
}else
if(sum < da.s)
{
c++;
}else
if(sum > da.s)
{
sum = sum - temp;
}
}
}
}
if(sum<da.s)
c=0;
if (c>0)
System.out.println(c);
else
System.out.println("not sufficient memory");
}
}
Well You should use ideone to format your code, and put a link to the problem, if you expect people to help you.
Anyways, I think that a public class should be the first thing in your code. Rest shall be below or nested inside. Try that.
Hey thanks for your help. But now there is an error i.e. "runtime error : exit code is 1". Can you help me in this please. This code is doing good on my local machine.
How do you run it? Correct signature for
main
ispublic static void main(String[] args)
(even if you don't useargs
), not justmain
without arguments.