last day (14 days later) » 

2:24 AM
1
A: Java Errors: Exception in thread "main" java.lang.RuntimeException

EmzFirst of, I recommend to properly indent your code, making it easier to read. Second as you are using char you can just check against the value of the character. char c = 'a' like that. If you increment c it then has the value of b. public class Letters { public static void main (String[] ar...

 
THANKS! I see I had a couple o.incorrect things going on. But the program is not outputting the letters in rows.. @emz
 
Emz
Care to clarify? It does print every letter on a new line, from the System.out.println(); and it is in order from just incrementing once every iteration.
 
10 letters per line @emz
 
Emz
Oh abcdefghij then a new line and klmnopqrst on the second? A hint of what to use is - 'a'; will give you which index you are working on. For the printChars (...) you can use - c1; to accomplish the same. I will leave that exercise to you for now. If you run into further problems don't hesitate to give a poke. But please do try first.
 
yes @emz ......
 
Emz
2:24 AM
I updated my comment.
 
sorry to bother you again
i totally suck when it comes to Java
Before i had String myrow = printRow();
System.out.println(myrow);
so im just not understanding how to incorporate this back into my code
 
Emz
I missunderstood your question a bit at first.
I updated my answer for your question now. It is working now.
I generally don't like giving out full-fledged solutions, so please make sure you understand it, if not, then do ask a question.
 
2:40 AM
Oh abcdefghij then a new line and klmnopqrst on the second? A hint of what to use is - 'a'; will give you which index you are working on. For the printChars (...) you can use - c1; to accomplish the same. I will leave that exercise to you for now. If you run into further problems don't hesitate to give a poke. But please do try first. – Emz 1 hour ago
 
Emz
(c+1 - 'a') will give you which iteration you are on.
c gets its initial value of 'a' meaning, the first iteration it is 'a'-'a', which equals to 0. Now for modulo (%) to work you need to add on to the initial value, hence the c+1 - 'a'.
For the 10th letter, in this case 'j' you get j+1 - a which is equal to 10.
10 is divisible by 10, so add a new line.
I am hitting the bed now, I will get back to the topic if you have any questions late tomorrow.
public static void printChars (char c1, char c2) {} just prints the characters from c1 to c2, if you enter 'e' and 'g' it will pring 'efg'.
Meaning
public static void main (String[] args) {
System.out.println("Print all characters between a and w");

for (char c = 'a'; c <= 'w'; c++) {
System.out.print(c);
if ((c+1 - 'a') % 10 == 0) {
System.out.println();
}
}

System.out.println("\n");

printChars ('d','z');
}
printChars ('a','w');
Try and play around with it. Good night.
 

last day (14 days later) »