Friday, November 24, 2017

Mixed Fractions Kattis Problem Solution In Java


//Nayeem Shahriar Joy,Applied Physics & Electronic Engineering, University of Rajshahi.
 
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set
 
public class Joy{
public static void main(String[] args) {
// Get input from the user w/ sentinel logic
Scanner in = new Scanner(System.in);
String s=in.nextLine();
String[]values=s.split(" ");
int a=Integer.parseInt(values[0]);
int b=Integer.parseInt(values[1]);
ArrayList<String>answers=new ArrayList<String>();
while(!(s.trim().equals("0 0")))
{
String[] mixedFunction=s.split(" ");
int A=Integer.parseInt(mixedFunction[0]);
int B=Integer.parseInt(mixedFunction[1]);
int frac=A/B;
int num=A%B;
answers.add(""+frac+" "+num+" / "+B);
s=in.nextLine();
}
for(int i=0;i<answers.size();i++)
{
System.out.println(answers.get(i));
}
}
}

No comments:

Post a Comment