How to print results of matched numbers with a spaceHow do I efficiently iterate over each entry in a Java Map?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?What's the simplest way to print a Java array?How do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?Why is subtracting these two times (in 1927) giving a strange result?Why does this code using random strings print “hello world”?Why is printing “B” dramatically slower than printing “#”?Would it make any difference giving arguments using scanner class instead of command line arguments?

Why didn't Stark and Nebula use jump points with their ship to go back to Earth?

Why did Windows 95 crash the whole system but newer Windows only crashed programs?

Word for giving preference to the oldest child

Is it okay for me to decline a project on ethical grounds?

Does Ubuntu reduce battery life?

How does Asimov's second law deal with contradictory orders from different people?

How can you tell the version of Ubuntu on a system in a .sh (bash) script?

What is this kind of symbol meant to be?

Embedded C - Most elegant way to insert a delay

Complaints from (junior) developers against solution architects: how can we show the benefits of our work and improve relationships?

How to efficiently shred a lot of cabbage?

Three Dots in Center Page

How can a circuit not have a neutral?

Efficiently finding furthest two nodes in a graph

why there is no “error” term in survival analysis?

What is a good example for artistic ND filter applications?

Are all French verb conjugation tenses and moods practical and efficient?

Is Ear Protection Necessary For General Aviation Airplanes?

Would it take any sort of amendment to make DC a state?

Is it possible for a particle to decay via gravity?

Can you continue the movement of a Bonus Action Dash granted by Expeditious Retreat if your Concentration is broken mid-move?

Is there a word or phrase that means 'works but not for the reason we expect it to'?

How can flights operated by the same company have such different prices when marketed by another?

Unknown indication below upper stave



How to print results of matched numbers with a space


How do I efficiently iterate over each entry in a Java Map?How do I read / convert an InputStream into a String in Java?How do I generate random integers within a specific range in Java?What's the simplest way to print a Java array?How do I convert a String to an int in Java?How do I fix android.os.NetworkOnMainThreadException?Why is subtracting these two times (in 1927) giving a strange result?Why does this code using random strings print “hello world”?Why is printing “B” dramatically slower than printing “#”?Would it make any difference giving arguments using scanner class instead of command line arguments?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















Just thought of a simple program to practice java coding and am stuck at the end part.,..



the code prints out the required answer (what numbers match from input compared to results for a 5 number lottery) but the answer is printed without spaces. I thought perhaps to add a "" when += to matchingNumbers but that didnt do anything!



import java.util.Scanner;
import java.util.Arrays;
public class LottoChecker

public static void main (String[] args)

Scanner in = new Scanner(System.in);
int [] yourNumbers = new int [5];
int yourInput, resultsInput;
int [] results = new int [5];
int currentNumber = 0;
String matchingNumbers = "";
for (int i=0; i<yourNumbers.length; i++)

System.out.println ("Enter your main numbers: " );
yourInput = in.nextInt();
yourNumbers[i]=yourInput;


for (int j=0; j<results.length; j++)

System.out.println("Enter the results from the main numbers: ");
resultsInput = in.nextInt();
results[j] = resultsInput;


System.out.println("Your Numbers: " +
Arrays.toString(bubbleSort(yourNumbers)));
System.out.println("The Results are: " +
Arrays.toString(results));

for (int i =0; i<yourNumbers.length;i++)

currentNumber = yourNumbers[i];
for (int j=0;j<results.length;j++)
if (currentNumber == results[j])

matchingNumbers += currentNumber + "";



System.out.println("Your matching numbers are: " +
matchingNumbers);



public static int [] bubbleSort(int arr[])

int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])


int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;

return arr;












share|improve this question



















  • 6





    Try adding " " instead of "". "" is an empty String

    – GBlodgett
    Mar 26 at 21:36












  • Use "Your matching numbers are:" and then += " " + currentNumber

    – Daniel Widdis
    Mar 26 at 21:37

















0















Just thought of a simple program to practice java coding and am stuck at the end part.,..



the code prints out the required answer (what numbers match from input compared to results for a 5 number lottery) but the answer is printed without spaces. I thought perhaps to add a "" when += to matchingNumbers but that didnt do anything!



import java.util.Scanner;
import java.util.Arrays;
public class LottoChecker

public static void main (String[] args)

Scanner in = new Scanner(System.in);
int [] yourNumbers = new int [5];
int yourInput, resultsInput;
int [] results = new int [5];
int currentNumber = 0;
String matchingNumbers = "";
for (int i=0; i<yourNumbers.length; i++)

System.out.println ("Enter your main numbers: " );
yourInput = in.nextInt();
yourNumbers[i]=yourInput;


for (int j=0; j<results.length; j++)

System.out.println("Enter the results from the main numbers: ");
resultsInput = in.nextInt();
results[j] = resultsInput;


System.out.println("Your Numbers: " +
Arrays.toString(bubbleSort(yourNumbers)));
System.out.println("The Results are: " +
Arrays.toString(results));

for (int i =0; i<yourNumbers.length;i++)

currentNumber = yourNumbers[i];
for (int j=0;j<results.length;j++)
if (currentNumber == results[j])

matchingNumbers += currentNumber + "";



System.out.println("Your matching numbers are: " +
matchingNumbers);



public static int [] bubbleSort(int arr[])

int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])


int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;

return arr;












share|improve this question



















  • 6





    Try adding " " instead of "". "" is an empty String

    – GBlodgett
    Mar 26 at 21:36












  • Use "Your matching numbers are:" and then += " " + currentNumber

    – Daniel Widdis
    Mar 26 at 21:37













0












0








0








Just thought of a simple program to practice java coding and am stuck at the end part.,..



the code prints out the required answer (what numbers match from input compared to results for a 5 number lottery) but the answer is printed without spaces. I thought perhaps to add a "" when += to matchingNumbers but that didnt do anything!



import java.util.Scanner;
import java.util.Arrays;
public class LottoChecker

public static void main (String[] args)

Scanner in = new Scanner(System.in);
int [] yourNumbers = new int [5];
int yourInput, resultsInput;
int [] results = new int [5];
int currentNumber = 0;
String matchingNumbers = "";
for (int i=0; i<yourNumbers.length; i++)

System.out.println ("Enter your main numbers: " );
yourInput = in.nextInt();
yourNumbers[i]=yourInput;


for (int j=0; j<results.length; j++)

System.out.println("Enter the results from the main numbers: ");
resultsInput = in.nextInt();
results[j] = resultsInput;


System.out.println("Your Numbers: " +
Arrays.toString(bubbleSort(yourNumbers)));
System.out.println("The Results are: " +
Arrays.toString(results));

for (int i =0; i<yourNumbers.length;i++)

currentNumber = yourNumbers[i];
for (int j=0;j<results.length;j++)
if (currentNumber == results[j])

matchingNumbers += currentNumber + "";



System.out.println("Your matching numbers are: " +
matchingNumbers);



public static int [] bubbleSort(int arr[])

int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])


int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;

return arr;












share|improve this question














Just thought of a simple program to practice java coding and am stuck at the end part.,..



the code prints out the required answer (what numbers match from input compared to results for a 5 number lottery) but the answer is printed without spaces. I thought perhaps to add a "" when += to matchingNumbers but that didnt do anything!



import java.util.Scanner;
import java.util.Arrays;
public class LottoChecker

public static void main (String[] args)

Scanner in = new Scanner(System.in);
int [] yourNumbers = new int [5];
int yourInput, resultsInput;
int [] results = new int [5];
int currentNumber = 0;
String matchingNumbers = "";
for (int i=0; i<yourNumbers.length; i++)

System.out.println ("Enter your main numbers: " );
yourInput = in.nextInt();
yourNumbers[i]=yourInput;


for (int j=0; j<results.length; j++)

System.out.println("Enter the results from the main numbers: ");
resultsInput = in.nextInt();
results[j] = resultsInput;


System.out.println("Your Numbers: " +
Arrays.toString(bubbleSort(yourNumbers)));
System.out.println("The Results are: " +
Arrays.toString(results));

for (int i =0; i<yourNumbers.length;i++)

currentNumber = yourNumbers[i];
for (int j=0;j<results.length;j++)
if (currentNumber == results[j])

matchingNumbers += currentNumber + "";



System.out.println("Your matching numbers are: " +
matchingNumbers);



public static int [] bubbleSort(int arr[])

int n = arr.length;
for (int i = 0; i < n-1; i++)
for (int j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])


int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;

return arr;









java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 21:35









LearningToCodeLearningToCode

92 bronze badges




92 bronze badges










  • 6





    Try adding " " instead of "". "" is an empty String

    – GBlodgett
    Mar 26 at 21:36












  • Use "Your matching numbers are:" and then += " " + currentNumber

    – Daniel Widdis
    Mar 26 at 21:37












  • 6





    Try adding " " instead of "". "" is an empty String

    – GBlodgett
    Mar 26 at 21:36












  • Use "Your matching numbers are:" and then += " " + currentNumber

    – Daniel Widdis
    Mar 26 at 21:37







6




6





Try adding " " instead of "". "" is an empty String

– GBlodgett
Mar 26 at 21:36






Try adding " " instead of "". "" is an empty String

– GBlodgett
Mar 26 at 21:36














Use "Your matching numbers are:" and then += " " + currentNumber

– Daniel Widdis
Mar 26 at 21:37





Use "Your matching numbers are:" and then += " " + currentNumber

– Daniel Widdis
Mar 26 at 21:37












1 Answer
1






active

oldest

votes


















2














An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366562%2fhow-to-print-results-of-matched-numbers-with-a-space%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.






    share|improve this answer





























      2














      An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.






      share|improve this answer



























        2












        2








        2







        An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.






        share|improve this answer













        An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 21:43









        oliver.goliver.g

        541 silver badge5 bronze badges




        541 silver badge5 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366562%2fhow-to-print-results-of-matched-numbers-with-a-space%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript