[Solved] I cannot process chars [closed]

[ad_1] Instead of setting a character variable which is discarded, I assume you want to use this character to build a new String. StringBuilder sb = new StringBuilder(); for (char ch : dna.toCharArray()) { switch (ch) { case ‘A’: sb.append(‘T’); break; case ‘T’: sb.append(‘A’); break; case ‘G’: sb.append(‘C’); break; case ‘C’: sb.append(‘G’); break; } } … Read more

[Solved] If else statements and subStrings (new to programming in Java)

[ad_1] You should print the prompt before you accept user input, otherwise you won’t know what you are entering. For example, in your code String Destination = S.nextLine(); System.out.println(“Specify :” + Destination); That first line will halt and wait for output with no prompt as what to enter. Changing around a few lines should get … Read more

[Solved] unable to get the expected output,i should get true but when executed i am getting false?

[ad_1] you just need to change you code likewise, if(str.substring(1,3).equals(a)){…} what you did wrong is , you have been used ‘==’ assignment operator, it is not comparing content(here, string) instead of it, it compare’s memory location between two compared string. it’s obvious to get false, because how is it possible ? that two different string … Read more

[Solved] One java file use another java file compile error

[ad_1] If you really want to manually call the compiler, make sure to build in a proper output directory (not .), use it as with a -classpath argument, and compile the classes in the right order (TreeNode before FPTree). Or use ant, maven, or an IDE. 0 [ad_2] solved One java file use another java … Read more

[Solved] How do] I call one method from a class to another class? [closed]

[ad_1] It Should be something like that: public class MyClass { public void setSerial(int ser) { serialNumber = ser; } public double computeArea() { return width*length; } } But that won’t work: public void displayBoxes(){ MyClass myClass = new MyClass(); DecimalFormat df = new DecimalFormat(“0.000”); System.out.println(toString()); System.out.println(“The rectangle with the serial number ” + myClass.setSerial(12345) … Read more

[Solved] Only allowing numbers to be taken from user input in java

[ad_1] Inside your while loop use the following code: System.out.print(“Enter the test score: “); while (!keyboard.hasNextInt()) {//Will run till an integer input is found System.out.println(“Only number input is allowed!”); System.out.print(“Enter the test score: “); keyboard.next(); } int tS = keyboard.nextInt(); //If input is a valid int value then the above while loop would not be … Read more

[Solved] How to choose proper if statements in linked list?

[ad_1] Consider the following Linked List: HEAD —> [“value2” | -]–> [“value3” | -]–> [“last_value” | null] Assuming current points to “value3”: HEAD —> [“value2” | -]–> [“value3” | -]–> [“last_value” | null] ↑ then current.next != null is true, since current.next is actually the “next” node. Now let’s assume current moved to “last_value”, now … Read more

[Solved] how to increment value of string variable?

[ad_1] A little bit simpler : public class Count { private static int count = 0; // resets the value to 0 public static void reset() { count = 0; } // updates the value public static String update() { count++; if(count == 1000) count = 1; return String.format(“%03d”, count); } // main() is used … Read more

[Solved] Creating a class with all of my functions in java

[ad_1] @Quincunx’s answer in the comments is correct, but writing whole programs like this violates all sorts of OO principles, and it’s not a good idea for readability, maintainability, etc. You probably want to go back and read some basic Java tutorials. For example, to use a method outside of the class that declares it, … Read more