Java Code Program for the given Question

Given three values of different data types. You are required to store these values in variables of corresponding data type and output them. Input: The first line of input contains integer T denoting the number of test cases. For each test case, there will be three space seperated values i.e Integer, String, Float.


4 Answers
1-4 of  4
4 Answers
  • import java.util.stream.LongStream;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.math.BigInteger;
    import java.util.ArrayList;
    import java.util.List;
    public class HelloWorld{ public static void main(String args[]) throws Exception
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = br.readLine(); int N = Integer.parseInt(line);
    ArrayList<Integer> inputs = new ArrayList<Integer>();
    for (int i = 0; i < N; i++)
    {
    inputs.add(Integer.valueOf(br.readLine()));
    }
    ArrayList<BigInteger> outputs = new ArrayList<BigInteger>();
    for(Integer input : inputs)
    {
    outputs.add(factorial(input));
    }
    for(BigInteger result: outputs){ System.out.println(result);
    }
    }
    private static BigInteger factorial(Integer input)
    {
    if(input == 1) return BigInteger.ONE;
    return factorial(input - 1).multiply(new BigInteger(String.valueOf(input)));
    }
    }

  • import java.util.stream.LongStream;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.math.BigInteger;
    import java.util.ArrayList;
    import java.util.List;
    public class HelloWorld{ public static void main(String args[]) throws Exception
    {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = br.readLine(); int N = Integer.parseInt(line);
    ArrayList<Integer> inputs = new ArrayList<Integer>();
    for (int i = 0; i < N; i++)
    {
    inputs.add(Integer.valueOf(br.readLine()));
    }
    ArrayList<BigInteger> outputs = new ArrayList<BigInteger>();
    for(Integer input : inputs)
    {
    outputs.add(factorial(input));
    }
    for(BigInteger result: outputs){ System.out.println(result);
    }
    }
    private static BigInteger factorial(Integer input)
    {
    if(input == 1) return BigInteger.ONE;
    return factorial(input - 1).multiply(new BigInteger(String.valueOf(input)));
    }
    }

  • import java.util.*;
    class a
    {
    public static void main(String arg[])
    {
      Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       for(int i=0;i<n;i++)
    {
       int  x=sc.nextInt();
       Integer i=new Integer(x);
       sc.nextLine();
        String  s=sc.next();
        float f=sc.nextFloat();
        Float f1=new Float(f);
        System.out.println(i+" "+s+" "+f1);
        
      }
    }
    }

Core Java

Didn't get the answer.
Contact people of Talent-Core Java directly by clicking here