I am facing trouble to submit a code in a coding platform.
Problem Statement
A local musician is putting on a concert to raise money for charity. The concert will be held in the town hall, a spacious venue perfectly suited for such an event.
- There are
r
rows of seats, each containing exactlys
seats. - At most one person can sit on a single seat (that is, two people cannot share a seat).
There is a problem - the concert may have been overbooked! This means that if everybody who bought tickets comes to the concert, some of them might have to stand.
Now the musician has approached you, not for advice, but for the answer to the following question:
if everybody who bought tickets arrives and tries to find a seat, how many people will end up sitting, and how many people will be standing?
This is my program:
package Prerequisite;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class Solution {
static private final String INPUT ="sitin.txt";
static private final String OUTPUT ="sitout.txt";
public static void main(String[] args) {
FileInputStream instream = null;
PrintStream outstream = null;
try {
instream = new FileInputStream (INPUT);
outstream = new PrintStream ( new FileOutputStream (OUTPUT));
System.setIn (instream);
System.setOut (outstream);
} catch (Exception e) {
System.err.println ( "Error Occurred." );
}
Scanner sc=new Scanner(System.in);
int r=sc.nextInt();
int s=sc.nextInt();
int ticket=sc.nextInt();
if((r*s)>=ticket)
{
System.out.println(ticket+" "+0);
}
else
{
System.out.println(r*s+" "+(ticket-r*s));
}
}
}
Input 7 12 100
Output 84 16