import java.util.*;
class EverySum
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int a,b=0;
System.out.println ("\n\t The number must be 50 or less");
System.out.print ("\n\t Enter the nth number = ");
a=in.nextInt();
try
{
if (a>50)
check.test();
else
{
for (int i=1;i<a;++i)
{
b+=i;
System.out.print ("\t "+b);
}
}
}
catch (IndexOutOfBoundsException e)
{
System.out.println ("\n\t Invalid number: "+e);
}
}
}
class check
{
static void test() throws IndexOutOfBoundsException
{
throw new IndexOutOfBoundsException (">50");
}
}
class EverySum
{
public static void main (String args[])
{
Scanner in = new Scanner (System.in);
int a,b=0;
System.out.println ("\n\t The number must be 50 or less");
System.out.print ("\n\t Enter the nth number = ");
a=in.nextInt();
try
{
if (a>50)
check.test();
else
{
for (int i=1;i<a;++i)
{
b+=i;
System.out.print ("\t "+b);
}
}
}
catch (IndexOutOfBoundsException e)
{
System.out.println ("\n\t Invalid number: "+e);
}
}
}
class check
{
static void test() throws IndexOutOfBoundsException
{
throw new IndexOutOfBoundsException (">50");
}
}
No comments:
Post a Comment