BlueJ - My program compiles with no errors but doesn't run
The reason your program compiles but doesn't run is because of the line s1=input.nextLine();
. At this line, the program is waiting for input from the user to use as the string s1
, but does not show the terminal in order for the user to give such input. A way you can get around this is to force the terminal to show itself before that line. I would recommend putting something like
System.out.println("Enter input:");
before the line, so that the terminal will show itself & the user can enter input into it. From there, you can work on the program like you would normally.
user3385542
Updated on June 04, 2022Comments
-
user3385542 almost 2 years
Hello I'm having problems with a program that's supposed to take in a string and then capitalize the first letters of each word using the Character Wrapper class.
import java.util.*; public class wrapper { public static void main(String[] args) { Scanner input= new Scanner(System.in); String s1; s1=input.nextLine(); s1= s1.trim(); int howLong= s1.length(); int i; int counter=0; char cho; for(counter=1; counter<= howLong+1; counter++) { cho=s1.charAt(counter); if(Character.isLetter (cho) && ! Character.isLetter(s1.charAt(counter-1))) { System.out.print( Character.toUpperCase(cho) ); } else { System.out.print(cho); } System.out.println(); } } }
That's the program so far, but while it compiles with no errors according to BlueJ, it doesn't run. Any help as to why this is happening would be great.
Edit: Changed the program to what I believe would make it not just print out the spaces that the char variable was initialized to, but it still does not run. Maybe there's something wrong with the loop?