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

  • SEARCH
  • Home
  • 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 9269683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:11:08+00:00 2026-06-18T15:11:08+00:00

Please have a look at the following java code import java.util.Scanner; public class Main

  • 0

Please have a look at the following java code

import java.util.Scanner;

public class Main
{
    static int mul=1;
    static String  convert;
    static  char[] convertChar ;
    static StringBuffer buffer = new StringBuffer("");

    public static void main(String[]args)
    {

        Scanner scan = new Scanner(System.in);

        int number=0;
        int loopValue = scan.nextInt();
       //System.out.println("print: "+loopValue);

        for(int i=0;i<loopValue;i++)
        {
            number = scan.nextInt();
           // System.out.println("print: "+number);

            for(int a=1;a<=number/2;a++)
            {
                if(number%a==0)
                {
                    //System.out.println(a);
                    mul = mul*a;
                    //System.out.println(mul);
                }
            }

           convert  = String.valueOf(mul);
           convertChar = convert.toCharArray();

           if(convertChar.length>4)
            {
               /*System.out.print(convertChar[convertChar.length-4]);
               System.out.print(convertChar[convertChar.length-3]);
               System.out.print(convertChar[convertChar.length-2]);
               System.out.print(convertChar[convertChar.length-1]);
               System.out.println();*/

               buffer.append(convertChar[convertChar.length-4]);
               buffer.append(convertChar[convertChar.length-3]);
               buffer.append(convertChar[convertChar.length-2]);
               buffer.append(convertChar[convertChar.length-1]);

                System.out.println(buffer);

            }
            else
            {
                System.out.println(mul);
            }

            //System.out.println(mul);
            mul = 1;
        }

    }
}

This code is built to compute the product of positive divisors of a given number. I have used scanner here because I don’t know how many inputs will be entered. That is why I can’t go something like

int a, b;

cin >> a >> b

in C++. All the inputs will be inserted by a test engine, into one single like like following

6 2 4 7 8 90 3456

How can I implement the Java “Scanner” using C++ ? Is there a header file for that? Please help!

  • 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-18T15:11:10+00:00Added an answer on June 18, 2026 at 3:11 pm

    You seem to be using Scanner to read one integer at a time from the standard input stream. This is easily accomplished with the extraction operator, operator>>.

    Replace this code:

        Scanner scan = new Scanner(System.in);
    
        int number=0;
        int loopValue = scan.nextInt();
       //System.out.println("print: "+loopValue);
    
        for(int i=0;i<loopValue;i++)
        {
            number = scan.nextInt();
           // System.out.println("print: "+number);
    

    With this:

        int number=0;
        int loopvalue=0;
        std::cin >> loopvalue;
    
        for(int i = 0; i < loopValue; i++)
        {
            std::cin >> number;
    

    You should check the value of std::cin after the >> operations to ensure that they succeeded.

    Refs:

    • http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html
    • http://en.cppreference.com/w/cpp/io/basic_istream/operator_gtgt
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

please have a look at the following code import java.util.ArrayList; import java.util.List; public class
Please have a look at following code : import java.util.ArrayList; import java.util.List; class Main{
Please have a look at the following code package Euler; import java.util.ArrayList; import java.util.List;
Please have a look at the following code package vcardtest; import java.io.*; import java.util.Iterator;
Please have a look at the following code DataBaseConnector.java import java.sql.*; import javax.swing.*; public
Please have a look at the following code Main.Java import java.awt.event.*; import java.awt.*; import
Please have a look at the following code import java.awt.GridLayout; import java.util.ArrayList; import java.util.HashMap;
Please have a look at the following code package normal; import java.io.*; import java.util.*;
Please have a look the following code import javax.swing.*; import java.awt.event.*; import java.awt.*; public
Please have a look at the following code import java.awt.*; import java.awt.event.*; import javax.swing.*;

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.