Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Console says I can't convert int to string while I'm not using int

I’m getting error at

String temporarytext = (b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + b10 + b11 + b12);

It says I can’t convert int to string while I’m not using int but I’m not trying to?
I’m only trying to conver char to string

import java.util.Scanner;

public class Encrypt
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Plaintext");
        
        String word1 = scan.next();
        String word2 = scan.next();
        String word3 = scan.next();
        
        String plaintext = word1 + word2 + word3;
        
        char a1 = plaintext.charAt(0);
        char a2 = plaintext.charAt(1);  
        char a3 = plaintext.charAt(2);  
        char a4 = plaintext.charAt(3);  
        char a5 = plaintext.charAt(4);
        char a6 = plaintext.charAt(5);  
        char a7 = plaintext.charAt(6);  
        char a8 = plaintext.charAt(7);  
        char a9 = plaintext.charAt(8);  
        char a10 = plaintext.charAt(9); 
        char a11 = plaintext.charAt(10);    
        char a12 = plaintext.charAt(11);
        
        char b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12;
        
        if (a1 == (char) 120)
            b1 = (char) 97; 
        if (a1 == (char) 121)
            b1 = (char) 98; 
        if (a1 == (char) 122)
            b1 = (char) 99; 
        else
            b1 = ((char)(3 + (int) a1));
        
        if (a2 == (char) 120)
            b2 = (char) 97; 
        if (a2 == (char) 121)
            b2 = (char) 98; 
        if (a2 == (char) 122)
            b2 = (char) 99; 
        else
            b2 = ((char)(3 + (int) a2));
        
        if (a3 == (char) 120)
            b3 = (char) 97;
        if (a3 == (char) 121)
            b3 = (char) 98; 
        if (a3 == (char) 122)
            b3 = (char) 99; 
        else
            b3 = ((char)(3 + (int) a3));    
        
        if (a4 == (char) 120)
            b4 = (char) 97; 
        if (a4 == (char) 121)
            b4 = (char) 98; 
        if (a4 == (char) 122)
            b4 = (char) 99;     
        else
            b4 = ((char)(3 + (int) a4));    
        
        if (a5 == (char) 120)
            b5 = (char) 97;
        if (a5 == (char) 121)
            b5 = (char) 98; 
        if (a5 == (char) 122)
            b5 = (char) 99;     
        else
            b5 = ((char)(3 + (int) a5));    
        
        if (a6 == (char) 120)
            b6 = (char) 97;
        if (a6 == (char) 121)
            b6 = (char) 98; 
        if (a6 == (char) 122)
            b6 = (char) 99;     
        else
            b6 = ((char)(3 + (int) a6));    
        
        if (a7 == (char) 120)
            b7 = (char) 97;
        if (a7 == (char) 121)
            b7 = (char) 98; 
        if (a7 == (char) 122)
            b7 = (char) 99;     
        else
            b7 = ((char)(3 + (int) a7));    
        
        if (a8 == (char) 120)
            b8 = (char) 97; 
        if (a8 == (char) 121)
            b8 = (char) 98;
        if (a8 == (char) 122)
            b8 = (char) 99; 
        else
            b8 = ((char)(3 + (int) a8));    
        
        if (a9 == (char) 120)
            b9 = (char) 97; 
        if (a9 == (char) 121)
            b9 = (char) 98; 
        if (a9 == (char) 122)
            b9 = (char) 99; 
        else
            b9 = ((char)(3 + (int) a9));    
        
        if (a10 == (char) 120)
            b10 = (char) 97;
        if (a10 == (char) 121)
            b10 = (char) 98;
        if (a10 == (char) 122)
            b10 = (char) 99;        
        else
            b10 = ((char)(3 + (int) a10));  
        
        if (a11 == (char) 120)
            b11 = (char) 97;
        if (a11 == (char) 121)
            b11 = (char) 98;
        if (a11 == (char) 122)
            b11 = (char) 99;        
        else
            b11 = ((char)(3 + (int) a11));  
        
        if (a12 == (char) 120)
            b12 = (char) 97;
        if (a12 == (char) 121)
            b12 = (char) 98;    
        if (a12 == (char) 122)
            b12 = (char) 99;    
        else
            b12 = ((char)(3 + (int) a12));                      
        
        String temporarytext = (b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8 + b9 + b10 + b11 + b12);
        
        String cipherword1 = temporarytext.substring(0, word1.length());
        String cipherword2 = temporarytext.substring(word1.length() + 1, word1.length() + word2.length() + 1);
        String cipherword3 = temporarytext.substring(word1.length() + word2.length() +2 , 14);
        
        String ciphertext = cipherword1 + " " + cipherword2 + " " + cipherword3;
        
        System.out.println("Ciphertext");
        System.out.println(ciphertext);     
    }
}   

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your code needs a lot of work, but to answer the question narrowly, you need to sort of "kick off" the string concatenation by starting with a string. Below I just use an empty string "" to get started. I also believe you need to convert your ints to chars to let the compiler know what you want to do.

   public static void main( String[] args ) {
      int b1 = 97;
      int b2 = 98;
      int b3 = 99;
      
      String s = "" + (char)b1 + (char)b2 + (char)b3;
      System.out.println( s );
   }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading