Trying to write some code to allow a user type in some text and then type in how many characters per line they would like to appear in the terminal and completely stumped, not even sure if I'm going in the right direction with this.
Here's what I got so far:
import javax.swing.JOptionPane ; public class SendAMessage { public static void main(String[] args) { String message, numberInput ; int textMaxLen, i, c ; c = 0 ; message = JOptionPane.showInputDialog(null,"Message : ") ; numberInput = JOptionPane.showInputDialog(null,"Characters per Message : ") ; textMaxLen = Integer.parseInt(numberInput) ; i = Integer.parseInt(numberInput) ; if( message.length() / textMaxLen <= 1) { System.out.println(message) ; }else{ for( c = 0 ; c != message.length() ; ) { if(i < textMaxLen) { System.out.println(i) ; }else{ System.out.println(message.substring(c, c+textMaxLen)) ; c = c+textMaxLen ; i = c ; } if(i < textMaxLen) { System.out.println(i) ; } } } } }
Any help would be greatly appreciated
The main problem is that in order for this to work the number of characters per line needs to divide into the number or characters from the user input exactly, if there is 3 characters left over from the user input and the user specified he wanted 4 characters per line it will not print the last line and give an error message