3 / 3
Jan 2011

import java.util.Scanner;
Some body help please !!!
unamused
goes without saying i see the correct out put on my ecllipse frowning cry

public class Main
{
public static void main (String args[])
{
int noofTree=0;
boolean flag=false;
int counter=0;
Scanner scan= new Scanner(System.in);
// System.out.print("Enter the No of Trees\n");
try{
noofTree= scan.nextInt();
}
catch(NumberFormatException nfe)
{
nfe.printStackTrace();
}
int []anArray;
// System.out.print("Enter the Co-ordinates\n");
anArray= new int[10];
for (int i=0;i {
try{
anArray[i]=scan.nextInt();
}
catch(NumberFormatException nfe)
{
nfe.printStackTrace();
}
System.out.print(anArray[i]);
}
int i=0;
int k=1;
int diff=0;
int max=0;
max=anArray[--noofTree];
diff=anArray[k]-anArray[i];
System.out.print("Diff="+diff);
k=1;
loop: for(int no=diff;no>0;no--)
{
int var=anArray[i];
while(var<=max)
{
var+=no;
if(var>max)
{
counter=0;
k=1;
continue loop;
}
if(var!=(anArray[k]))
{
counter++;
}
if (var==anArray[k])
{
if(var==max)
{
flag=true;
System.out.print(counter);
System.exit(1);
}
if(var<=anArray[k])
{
k++;
}
}
}
}
}
}

  • created

    Jan '11
  • last reply

    Jan '11
  • 2

    replies

  • 245

    views

  • 2

    users

Proble was with System.exit(1) after using System.exit(0) got rid of Run Time error

Suggested Topics

Want to read more? Browse other topics in JAVA based languages or view latest topics.