Java Debugging Problem *Help!*

  • #1
Here's what I wrote , but theres no output.. It is suppose to read a line typed from the user and enter whatever the input was with the letter after the ones inputted. plz help

import java.util.Scanner;

class ProblemS2 {

static Scanner sc=new Scanner(System.in);

public static void main(String[] args){

System.out.print("Input the word:");

String code =sc.next();



System.out.println("Time to decipher this...");

char c;


char[] letteroutput = { 'A', 'B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };

for(int i=0;i<code.length();i++) {
c = code.charAt(i);



for(int j=0; j <letteroutput.length; i++) {

if(letteroutput[j]==c)
System.out.println(letteroutput[j+1]);
else
break;


}





}

}}
 

Answers and Replies

  • #2
161
0
I don't know what is it that you wan't to do but for starters 'A' and 'a' are not the same thefore if you input "java" nothing will happen since 'j' does not match 'J', maybe you can try String code =sc.next().toUpperCase();?
 
  • #3
Let's say I input MOO

the output would be NPP

N is after M
P is after O

I tried with Caps, does the same thing
 
  • #4
157
1
for(int j=0; j <letteroutput.length; i++ ) {

Can't be bothered to run through your algo, but this jumped out at me as I was skimming this thread. Should be j++ if you want j to ever change. :P
 
  • #5
Oh I just fixed that but then I found out the real problem... The Else statement I had cause the program to output nothing since it always broke out of my loop. Thx for help
 

Related Threads on Java Debugging Problem *Help!*

  • Last Post
2
Replies
32
Views
406
  • Last Post
Replies
9
Views
3K
Replies
2
Views
1K
  • Last Post
Replies
1
Views
585
  • Last Post
2
Replies
31
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
7
Views
3K
  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
2
Views
2K
Top