# I am a beginner, please help!

**URL:** <https://discourse.processing.org/t/i-am-a-beginner-please-help/25336>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [November 11, 2020, 3:50am UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336 "2020-11-11T03:50:22Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![AzizurRahman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/azizurrahman/32/11064_2.png) [@AzizurRahman](https://discourse.processing.org/u/AzizurRahman)\
**Post date:** [November 11, 2020, 3:50am UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/1 "2020-11-11T03:50:22Z")

</div>

i need to make something in which when user inputs some string it got converted into another sets of string

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 11, 2020, 7:20am UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/2 "2020-11-11T07:20:37Z")

</div>

Hello and welcome to the forum !  
Great to have you here!!

Basically when you have two Strings (source and cipher):

- `for`-loop over the user input (another String) :

- Use charAt() and indexOf() to get the position of the current letter in the first long String `source`. Store it in a variable `int myIndex`

- Use myIndex with charAt() in the 2nd long String cipher with println() please

Show your code (as far as you got) so we can help you.

Warm regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![AzizurRahman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/azizurrahman/32/11064_2.png) [@AzizurRahman](https://discourse.processing.org/u/AzizurRahman)\
**Post date:** [November 11, 2020, 8:44pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/3 "2020-11-11T20:44:05Z")

</div>

So Far I wrote this and its giving error. I really dont know what else to change. Please help

import javax.swing.JOptionPane;  
//String user;  
String new\_String="";

void size(){  
size(500,500);  
}

void draw(){  
String source=“0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”;  
String cipher="#A8fZKnVv0Tme5Eh61QGdubFt4qBsgOWM9DjIrcLzlUJ3NSaX7wpoiC2xPYRkyH" ;  
String user = JOptionPane.showInputDialog(null, "Type anything you need to covert into cipher ");

for (int i=0; i\<user.length(); i++)  
char current= user.charAt(i);

for(int j=0; j\<source.length(); j++){  
if(source.charAt(j) == current){  
new\_String += cipher.charAt(j);

```
   println(new_String);
  
   }

```

}  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 11, 2020, 8:52pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/4 "2020-11-11T20:52:14Z")

</div>

Does it work? What does it do wrong?

Check my previous post again

---

<div class="post-metadata">

**Author:** ![AzizurRahman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/azizurrahman/32/11064_2.png) [@AzizurRahman](https://discourse.processing.org/u/AzizurRahman)\
**Post date:** [November 11, 2020, 8:56pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/5 "2020-11-11T20:56:35Z")

</div>

char current= user.charAt(i); \>\>\>\>\>\>  
At this particular line there is an error : Syntax error, insert “. class” to complete Expression.

As far as I know it should run ! but still not working ☹

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 11, 2020, 9:06pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/6 "2020-11-11T21:06:10Z")

</div>

here…

you need to declare current before setup() so it’s a global var

doesn’t do what you want of course

```auto

import javax.swing.JOptionPane;
//String user;
String new_String="";

char current1;

void size() {
  size(500, 500);
}

void draw() {
  String source="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  String cipher="#A8fZKnVv0Tme5Eh61QGdubFt4qBsgOWM9DjIrcLzlUJ3NSaX7wpoiC2xPYRkyH" ;
  String user = JOptionPane.showInputDialog(null, "Type anything you need to covert into cipher ");

  for (int i=0; i<user.length(); i++)
    current1 = user.charAt(i);

  for (int j=0; j<source.length(); j++) {
    if (source.charAt(j) == current1) {
      new_String += cipher.charAt(j);
      println(new_String);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![AzizurRahman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/azizurrahman/32/11064_2.png) [@AzizurRahman](https://discourse.processing.org/u/AzizurRahman)\
**Post date:** [November 11, 2020, 9:07pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/7 "2020-11-11T21:07:59Z")

</div>

Thanks a Lot to you brother . I got it now \<3

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 11, 2020, 9:11pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/8 "2020-11-11T21:11:38Z")

</div>

well done, congratulations!

Mind showing your code?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 11, 2020, 9:58pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/9 "2020-11-11T21:58:58Z")

</div>

please note, the name of the function is `setup()` (not size)

```auto
void setup() { // !!!
  size(500, 500);
}

```

---

<div class="post-metadata">

**Author:** ![AzizurRahman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/azizurrahman/32/11064_2.png) [@AzizurRahman](https://discourse.processing.org/u/AzizurRahman)\
**Post date:** [November 11, 2020, 11:10pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/10 "2020-11-11T23:10:07Z")

</div>

\<\<\<\<\<\<\<\<\<\<\<\<Thanks for your effort. I saw it later.  
I have another question like there is a bug. When I input multiple strings at a time it only gives the output for one only. Such as if I type only one one letter then the output is fine but if I type my name “aziz” then the output is “j” which means it is giving the output for the last letter of my name only. But I wanted to make it in such a way so that the output is equal to the user input. \>\>\>\>\>\>\>\>\>\>\>\>\>\>

import javax.swing.JOptionPane;  
String user;  
String new\_String="";  
char current;

void setup(){  
size(1000,1000);  
}

void draw(){  
String source=“0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”;  
String cipher="#A8fZKnVv0Tme5Eh61QGdubFt4qBsgOWM9Dj IrcLzlUJ3NSaX7wpoiC2xPYRkyH" ;  
String user = JOptionPane.showInputDialog(null, "Type anything you need to covert into cipher ");

for (int i=0; i\<user.length(); i++)  
current= user.charAt(i);

for(int j=0; j\<source.length(); j++){  
if(source.charAt(j) == current){  
new\_String += cipher.charAt(j);

println(new\_String);  
background(160);

textSize(40);  
text(new\_String, 30,40);

}  
}  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 11, 2020, 11:32pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/11 "2020-11-11T23:32:15Z")

</div>

> [@AzizurRahman](#):
>
> for(int j=0; j\<source.length(); j++){

You need { after this line

and close it before the line with text() with }

---

<div class="post-metadata">

**Author:** ![AzizurRahman](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/azizurrahman/32/11064_2.png) [@AzizurRahman](https://discourse.processing.org/u/AzizurRahman)\
**Post date:** [November 11, 2020, 11:41pm UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/12 "2020-11-11T23:41:25Z")

</div>

Sorry I tried that but Didn’t work its still only giving output for the single inputs . I made some change in the code though now.

import javax.swing.JOptionPane;  
String user;  
String new\_String="";  
char current;

void setup(){  
size(1000,1000);  
background(150);  
}

void draw(){  
String source=“0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”;  
String cipher="#A8fZKnVv0Tme5Eh61QGdubFt4qBsgOWM9Dj IrcLzlUJ3NSaX7wpoiC2xPYRkyH" ;  
String user = JOptionPane.showInputDialog(null, "Type anything you need to covert into cipher ");

for (int i=0; i\<user.length(); i++)  
current= user.charAt(i);

for(int j=0; j\<source.length(); j++){  
if(source.charAt(j) == current){  
new\_String += cipher.charAt(j);

view();

}  
}  
}

void view(){  
println(new\_String);  
textSize(40);  
text(new\_String, 30,40);  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [November 12, 2020, 2:01am UTC](https://discourse.processing.org/t/i-am-a-beginner-please-help/25336/13 "2020-11-12T02:01:06Z")

</div>

Believe me when I say you need those {}

You know, in the first for-loop you loop over the letters of the user input and evaluate current.

But the first loop at the moment is only

```auto
  for (int i=0; i<user.length(); i++)
    current= user.charAt(i);

```

With the brackets { } you can extend how far the for loop reaches.

It must encompass the whole area and the next for-loop. So place the } after the 2nd for-loop.

It works here by the way.

Besides, check out `indexOf()` command in the reference, you don’t really need the 2nd for-loop: [https://www.processing.org/reference/String\_indexOf\_.html](https://www.processing.org/reference/String_indexOf_.html)

Warm regards,

Chrisir
