problem with the result of a two-dimensional array
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters = 0;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if (tab[i][j] == tab[i][k]) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
}
letters = 0;
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
}
letters = 0;
}
}
Why does my program display a different result than expected?
the same characters an letters for BlackBerry, why?
result:
in this word : Apple there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : Jolla there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : Samsung there are at least two of the same characters
in this word : Apple there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
in this word : Jolla there are at least two of the same characters
java arrays
add a comment |
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters = 0;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if (tab[i][j] == tab[i][k]) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
}
letters = 0;
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
}
letters = 0;
}
}
Why does my program display a different result than expected?
the same characters an letters for BlackBerry, why?
result:
in this word : Apple there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : Jolla there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : Samsung there are at least two of the same characters
in this word : Apple there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
in this word : Jolla there are at least two of the same characters
java arrays
2
What is the expected result?
– GBlodgett
Nov 12 at 18:47
1
You don't appear to need a loop forj
. I would step through the code in your debugger until you get a line which doesn't do what you expect.
– Peter Lawrey
Nov 12 at 18:48
How should the code look like?
– Foxal
Nov 12 at 18:56
add a comment |
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters = 0;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if (tab[i][j] == tab[i][k]) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
}
letters = 0;
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
}
letters = 0;
}
}
Why does my program display a different result than expected?
the same characters an letters for BlackBerry, why?
result:
in this word : Apple there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : Jolla there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : Samsung there are at least two of the same characters
in this word : Apple there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
in this word : Jolla there are at least two of the same characters
java arrays
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters = 0;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if (tab[i][j] == tab[i][k]) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
}
letters = 0;
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
k = j;
while (k < tab[i].length - 1) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32) letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
}
letters = 0;
}
}
Why does my program display a different result than expected?
the same characters an letters for BlackBerry, why?
result:
in this word : Apple there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : BlackBerry there are at least two identical letters
in this word : Jolla there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : Samsung there are at least two of the same characters
in this word : Apple there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
in this word : Jolla there are at least two of the same characters
java arrays
java arrays
asked Nov 12 at 18:45
Foxal
1
1
2
What is the expected result?
– GBlodgett
Nov 12 at 18:47
1
You don't appear to need a loop forj
. I would step through the code in your debugger until you get a line which doesn't do what you expect.
– Peter Lawrey
Nov 12 at 18:48
How should the code look like?
– Foxal
Nov 12 at 18:56
add a comment |
2
What is the expected result?
– GBlodgett
Nov 12 at 18:47
1
You don't appear to need a loop forj
. I would step through the code in your debugger until you get a line which doesn't do what you expect.
– Peter Lawrey
Nov 12 at 18:48
How should the code look like?
– Foxal
Nov 12 at 18:56
2
2
What is the expected result?
– GBlodgett
Nov 12 at 18:47
What is the expected result?
– GBlodgett
Nov 12 at 18:47
1
1
You don't appear to need a loop for
j
. I would step through the code in your debugger until you get a line which doesn't do what you expect.– Peter Lawrey
Nov 12 at 18:48
You don't appear to need a loop for
j
. I would step through the code in your debugger until you get a line which doesn't do what you expect.– Peter Lawrey
Nov 12 at 18:48
How should the code look like?
– Foxal
Nov 12 at 18:56
How should the code look like?
– Foxal
Nov 12 at 18:56
add a comment |
1 Answer
1
active
oldest
votes
Is this result your expect?
Output :
in this word : BlackBerry there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
Code :
public static void main(String args) {
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
letters = 0;
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if (tab[i][j] == tab[i][k])
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
break;
}
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32)
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
break;
}
}
letters = 0;
}
}
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%2f53268287%2fproblem-with-the-result-of-a-two-dimensional-array%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
Is this result your expect?
Output :
in this word : BlackBerry there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
Code :
public static void main(String args) {
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
letters = 0;
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if (tab[i][j] == tab[i][k])
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
break;
}
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32)
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
break;
}
}
letters = 0;
}
}
add a comment |
Is this result your expect?
Output :
in this word : BlackBerry there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
Code :
public static void main(String args) {
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
letters = 0;
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if (tab[i][j] == tab[i][k])
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
break;
}
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32)
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
break;
}
}
letters = 0;
}
}
add a comment |
Is this result your expect?
Output :
in this word : BlackBerry there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
Code :
public static void main(String args) {
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
letters = 0;
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if (tab[i][j] == tab[i][k])
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
break;
}
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32)
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
break;
}
}
letters = 0;
}
}
Is this result your expect?
Output :
in this word : BlackBerry there are at least two identical letters
in this word : Samsung sum of characters in the word > 255
in this word : Nokia sum of characters in the word > 255
in this word : Apple sum of characters in the word > 255
in this word : BlackBerry sum of characters in the word > 255
in this word : Alcatel sum of characters in the word > 255
in this word : Sony sum of characters in the word > 255
in this word : Jolla sum of characters in the word > 255
in this word : Nokia there is at least one character 'i'
in this word : BlackBerry there are at least two of the same characters
in this word : Alcatel there are at least two of the same characters
Code :
public static void main(String args) {
char tab = {
{'S', 'a', 'm', 's', 'u', 'n', 'g'},
{'N', 'o', 'k', 'i', 'a'},
{'A', 'p', 'p', 'l', 'e'},
{'B', 'l', 'a', 'c', 'k', 'B', 'e', 'r', 'r', 'y'},
{'A', 'l', 'c', 'a', 't', 'e', 'l'},
{'S', 'o', 'n', 'y'},
{'J', 'o', 'l', 'l', 'a'},
};
int letters;
int k = 0;
int licz = 0;
for (int i = 0; i < tab.length; i++) {
letters = 0;
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if (tab[i][j] == tab[i][k])
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two identical letters");
System.out.println();
break;
}
}
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
licz += (int) (tab[i][j]);
}
if (licz > 255) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" sum of characters in the word > 255");
System.out.println();
}
licz = 0;
}
letters = 0;
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length; j++) {
if (tab[i][j] == 'i')
letters++;
}
if (letters > 0) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there is at least one character 'i'");
System.out.println();
}
letters = 0;
}
System.out.println();
System.out.println();
for (int i = 0; i < tab.length; i++) {
for (int j = 0; j < tab[i].length-1; j++) {
k = j+1;
while (k < tab[i].length) {
if ((int) (tab[i][j]) == (int) (tab[i][k]) || (int) (tab[i][j]) == (int) (tab[i][k]) - 32)
letters++;
k++;
}
if (letters == 2) {
System.out.print("in this word : ");
for (int l = 0; l < tab[i].length; l++)
System.out.print(tab[i][l]);
System.out.print(" there are at least two of the same characters");
System.out.println();
break;
}
}
letters = 0;
}
}
edited Nov 16 at 9:44
answered Nov 16 at 8:05
ishi ya
11
11
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53268287%2fproblem-with-the-result-of-a-two-dimensional-array%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
2
What is the expected result?
– GBlodgett
Nov 12 at 18:47
1
You don't appear to need a loop for
j
. I would step through the code in your debugger until you get a line which doesn't do what you expect.– Peter Lawrey
Nov 12 at 18:48
How should the code look like?
– Foxal
Nov 12 at 18:56