Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting a sentence to an array and delete characters and print new sentence
    text
    copied!<p>DISCLAIMER: This is a homework assignment </p> <p>Goal of the program is: ask a sentence and then: - convert upper to lowercase <strong>(without using .toLowercase() )</strong> - remove all characters that are not a-z, A-Z and 0-9 - print new sentence - ... something more BUT not important for. </p> <p>Ok, so what I did. </p> <ul> <li>I converted my String (sentence) to a char array. </li> <li>I created a for loop to loop through all chars in my array</li> <li>If a char is a uppercase I converted it to a lowercase using ASCII</li> </ul> <p>The problem I experience is: - It looks like I change the char C but it's NOT stored as a lowercase in my array? - How do I detect the non-allowed characters, and delete this from my array?</p> <p>My code: </p> <pre><code>import java.util.Scanner; public class sentence { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String zin = ""; System.out.print("Voer een zin in: "); if (scanner.hasNextLine()) zin = scanner.nextLine().trim(); if (zin.equals("")) { System.out.print("Geen Invoer!"); System.exit(0); } char[] zinArray = zin.toCharArray(); for (int i = 0; i &lt; zinArray.length; i++) { char c = zinArray[i]; if (c &gt;= 'A' &amp;&amp; c &lt;= 'Z') { c = (char)(c + 32); } else if (c &gt;= 58 &amp;&amp; c &lt;= 64) { } else if (c &gt;= 91 &amp;&amp; c &lt;= 96) { } else if (c 123 &amp;&amp; c &lt;= 126) { } } } } </code></pre> <p>Can anyone point me in the right direction? </p> <p>Thanks :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload