Murderer00's blog

By Murderer00, history, 4 years ago, In English

*******Guys my output is correct but the computers checks it wrong, any suggestions about this?********

Write a program that takes two integers as input(one per line) and prints their sum as output.

For example,

For the input provided as follows:

2

3

The output of the program will be:

5

Provided code

Import java.io.*;
Public class Main
{
Public static void main(String [] args) throws java.lang.Exception{
String line;
DataInputStream in = new DataInputStream(System.in);
While((line=in.readLine())!=null){
}
}
}
}

My Personal Code

package a;

//The solutions should be written, for compiler compatibility : j2se jdk 8u51

import java.io.*;

public class Main
{  
public static void main (String[] args) throws java.lang.Exception
{ 
//use the following code to fetch input from console 
String line;

int first; int second; int total; int i;

DataInputStream in = new DataInputStream(System.in); 

System.out.println("For the input provided as follows: "+"\n");
while((line=in.readLine())!=null)    
{ 


int game []= new int[2];
int came [] = new int[2];
for( i = 0;i<2;i++) {
game[i]=Integer.parseInt(line);
came[i]=Integer.parseInt(in.readLine());
System.out.println(game[i]);
System.out.println(came[i]); 
break;  
}
for( i = 0;i<2;i++) {
if(game[i]<0 && came[i]<0) {
total = game[i]+came[i];
System.out.println("The output of the program will be:" +"\n"+total);
break;
}
else if(game[i]>0 && came[i]<0) {
total = game[i]+came[i];
System.out.println("The output of the program will be:" +"\n"+total);
break;
}
else if(game[i]<0 && came[i]>0) {
total = game[i]+came[i];
System.out.println("The output of the program will be:" +"\n"+total);
break;
}
else if(game[i]>0 && came[i]>0) {
total = game[i]+came[i];
System.out.println("The output of the program will be:" +"\n"+total);
break;
}
else if (game[i]==0 && came[i]==0) {
total = game[i]+came[i];
System.out.println("The output of the program will be:" +"\n"+total);
break;
}

}
} 
}  
}

Errors from the computer checker

0 out of 4 Test case Failed

  1. Two positive integers
  2. Two negative integers
  3. one positive and one negative integer.
  4. corner case for zero

Full text and comments »

  • Vote: I like it
  • -17
  • Vote: I do not like it

By Murderer00, history, 4 years ago, In English

-Problem--

Write a program that takes a single linked list of integers (from 0 to 10) of positive size N and gives As output the number that occurs the maximum number of times, from the inputted list. The input will be given in one line in the following format. N a1 a2 a3 a4 a5 … an ‘N’ is the size of the list and a1,a2,a3,… an, are the integers present on the list indicating that a1 has a link to a2,a2 has a link to a3 and so on. If more than one number appear the maximum number of times, you should Give as output the greatest one.

Example

Case 1: For the input provided as follows: 7 1 5 1 4 9 0 4 Output program will be: 4 Description: Both 1 and 4 appear the maximum number of times(two times), but 4 is The greatest one out of the two, so the output is 4.

Case 2: For the input provide as follows: 7 1 10 0 5 2 3 9 Output of the program will be: 10 Description: All number appear only once, so you should choose the greatest one that is 10.

--------Provided Code to Start------------------------------------------------------------------------------------------------

Import java.io.*; Public class Main { Public static void main(String [] args) throws java.lang.Exception{ String line; DataInputStream in = new DataInputStream(System.in); While((line=in.readLine())!=null){ } } }

}

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it