dimanche 29 novembre 2020

Array not finding value [duplicate]

I'm trying to write a program that takes DNA string value and converts to RNA. Whenever I assign values to specific indexes in my array, It won't see the value in my if statements. It doesn't see the letters at all. I've tried using sc.nextLine() instead of sc.next() in line 30 and that doesn't work at all. Any idea what might be going on?

import java.util.Arrays;
import java.util.List;


class Main {

  String[] dna;
  public Scanner sc = new Scanner(System.in);
    
    
  public static void main(String[] args) {
    Main obj = new Main();

    obj.takeUsr();

  }
  public void takeUsr(){
    System.out.print("How many letters: ");

    int count = sc.nextInt();
    
    int value = 0;
    
    dna = new String[count];
    while(count>0){
      
      
      System.out.print("Input letter:");
      dna[value] = sc.next();
      System.out.println("");
      value++;
      count--;
    }
    value = 0;
    int count2 = dna.length;
    while(count2 > 0){
      System.out.println(dna[value]);
      
      if(dna[value] == "A"){
        //dna[value] = "U";
        System.out.print("U");
        

      }

      else if(dna[value] == "U"){
        //dna[value] = "A";
        System.out.print("A");
      }

      else if(dna[value] == "C"){
        //dna[value] = "T";
        System.out.print("T");
      }

      else if(dna[value] == "G"){
        //dna[value] = "C";
        System.out.print("C");
      }
      else{
        break;
      }
      System.out.println("Success!");
      value++;
      count2--;
    }
  }
}

Aucun commentaire:

Enregistrer un commentaire