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;
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
add a comment |
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
6
Try adding" "
instead of""
.""
is an emptyString
– GBlodgett
Mar 26 at 21:36
Use"Your matching numbers are:"
and then+= " " + currentNumber
– Daniel Widdis
Mar 26 at 21:37
add a comment |
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
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
java
asked Mar 26 at 21:35
LearningToCodeLearningToCode
92 bronze badges
92 bronze badges
6
Try adding" "
instead of""
.""
is an emptyString
– GBlodgett
Mar 26 at 21:36
Use"Your matching numbers are:"
and then+= " " + currentNumber
– Daniel Widdis
Mar 26 at 21:37
add a comment |
6
Try adding" "
instead of""
.""
is an emptyString
– 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
add a comment |
1 Answer
1
active
oldest
votes
An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.
add a comment |
An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.
add a comment |
An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.
An elegant solution would be using StringJoiner(" ") and then add the numbers on each iteration.
answered Mar 26 at 21:43
oliver.goliver.g
541 silver badge5 bronze badges
541 silver badge5 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
6
Try adding
" "
instead of""
.""
is an emptyString
– GBlodgett
Mar 26 at 21:36
Use
"Your matching numbers are:"
and then+= " " + currentNumber
– Daniel Widdis
Mar 26 at 21:37