Java Debugging Java Code for User Input Decryption

  • Thread starter Thread starter crimsondarkn
  • Start date Start date
  • Tags Tags
    Debugging Java
AI Thread Summary
The discussion revolves around a Java program intended to take user input and output the next letter in the alphabet for each character entered. The initial code fails to produce output due to case sensitivity issues, as lowercase and uppercase letters are treated differently. A suggested solution is to convert the input to uppercase using `String code = sc.next().toUpperCase();`. Additionally, a critical error in the loop structure is identified; the inner loop's increment should be `j++` instead of `i++` to ensure it iterates correctly through the `letteroutput` array. The program's logic is further hindered by an incorrect `else` statement that prematurely exits the loop, preventing any output. After addressing these issues, the expected output for the input "MOO" would be "NPP," as each letter is replaced by the subsequent letter in the alphabet.
crimsondarkn
Messages
13
Reaction score
0
Here's what I wrote , but there's 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. please 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;


}





}

}}
 
Technology news on Phys.org
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();?
 
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
 
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
 
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
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...
Back
Top