codechef program #1 :Life, the Universe, and Everything

Photo courtesy:codechef
I started codechef..PROBLEM STATEMENT:
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.
MY SOLUTION:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author lol ik
*/
public class NewClass {
public static void main(String args[])
{
int i=0,j=0,c;
// int[] a =new int[10];
Scanner in=new Scanner(System.in);
try{
do
{
c=in.nextInt();
if(c<100&&c>-100&&c!=42){
System.out.println(c);
i++;
}
}while(c<100&&c>-100&&c!=42);
/* while(a[j]!=42)
{
System.out.println(a[j]);
j++;
}*/
}
catch( ArrayIndexOutOfBoundsException e )
{
System.out.println("Do Nothing");
}
}
}
Posted by lol ik
Comments
Post a Comment