Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:40:03+00:00 2026-06-04T04:40:03+00:00

I wrote a very short program for an easy programming competition problem with an

  • 0

I wrote a very short program for an easy programming competition problem with an online judger (http://acm.sgu.ru/problem.php?contest=0&problem=184) but for some reason I was getting a runtime error on the 21st test (it doesn’t specify what exactly the runtime error is). So I rewrote the code and it now does not give a runtime error, but I can’t figure out why this code should work while the original did not. Here is the working code:

Scanner scan = new Scanner(System.in);
int[] arr1 = new int[3];
int[] arr2 = new int[3];
for (int i = 0; i <= 2; i++) arr1[i] = scan.nextInt();
for (int i = 0; i <= 2; i++) arr2[i] = scan.nextInt();
System.out.println(Math.min(arr1[0]/arr2[0], Math.min(arr1[1]/arr2[1], arr1[2]/arr2[2])));

Here is the nonworking code:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] arr1 = in.readLine().split(" ");
String[] arr2 = in.readLine().split(" ");
int flour = Integer.parseInt(arr1[0])/Integer.parseInt(arr2[0]);
int milk = Integer.parseInt(arr1[1])/Integer.parseInt(arr2[1]);
int cabbage = Integer.parseInt(arr1[2])/Integer.parseInt(arr2[2]);
System.out.println(Math.min(cabbage, Math.min(flour, milk)));

I at first tried changing the BufferedReader to Scanner in the nonworking code and using in.nextLine() but that didn’t work. I then thought maybe there was a division by zero going on but the problem conditions preclude it and that should still be a problem in the working code, so I’m at a loss as to why the first works but the second does not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:40:04+00:00Added an answer on June 4, 2026 at 4:40 am

    It fails when the input is just separated by spaces without any line breaks. You get a NPE in the non-working code or when waiting for input then you exceed the timelimit of 0.5s for this test since your program blocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a very short program that parses a program using python and converts
Sometimes I write very short assembly functions like function SeniorBit(Value: LongWord): Integer; asm OR
I am trying to learn Android app development and wrote a very simple app
I'm very new to C#. My boss asked me to wrote some code using
I am experiencing some very odd timing behavior from a function I wrote. If
I'm VERY new to Linq. I have an application I wrote that is in
I'm trying to write a very simple image processing program for fun and practice.
I'm trying to write a very simple program, I want to print out the
I have a program that I use as an alt-tab replacement. I wrote it
I wrote a very basic jquery script to obtain the src attribute from my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.