This is a two part question. 1) how do I print all userinput if the loop runs more than once , I am aware the old string assigned to the variable gets erased each time. 2) how do i calculate the total task duration across all tasks for the amount of times the loop runs. thanks. Answer You can create
Tag: loops
Remove duplicate letters from a string sentence while keeping the spaces from the sentence
I am trying to take a sentence that a user has entered into a String variable and remove the duplicate letters while keeping the spaces in the sentence. For example if a user enters “hello my name is danny” it will return “Helo my nam is dn”. To do this I have already tried this code: This code however doesn’t
Do a task with interval in a loop
I already saw many question here but nothing worked for me. I wanted to set the text in a text view after every 1 second. This is what I tried: This does the task immediately and only the last number is seen. Then this: in this the screen shows blank white and after 90 seconds, I see the last number.
How to obtain the last number different to zero in an array in Java
I have for example this array: And I want to find the last number of the array different to 0. In this case, my output should be: 9.0 My code is: But it doesn’t work. I need to highlight that the size of the array1 is always the same. But the non-zero numbers can change, in any case, all the
How to print number 1 to 10(in that sequence only)using loops(java) if int i = 10
Output must be 1 2 3 4 5 6 7 8 9 10 I have tried While loop but it prints from 10 to 1 Answer Assuming you must use i with an initial value of 10.
Java Calculator program issue
I am trying to develop a calculator program that inputs an arithmetic expression of the form number operator number = and computes the result of the expression. The expression will be evaluated from left to right not considering regular operator precedence. For example, the expression 14 – 5 * 3 = will produce 27.0. The value = displays the final
Method that takes an int array and a value and returns the index of that value in the array
I’ve spent like an hour trying to figure this one out and I couldn’t. This is an exercise for a Java elective course I am taking and I could use some help. Write a method linearSearch() that takes an array of integers, and an integer value. It should then return the index of the value inside the array (by using
How to end while loop for integer gathering array in java?
I am wring a program that askes the user to give any value they want as long as it is a whole number, and that value will be placed in a array. They can do this asmany times as they would like, until they add -1 to the array. I am having a hard time figurig out how to get
Problems using circular array to take inputs and stop/print the last 10 elements once “-1” is entered
I have a Java program that should be doing what the above title describes. Unfortunately, I am now having the issue of having nothing but zeros and a Error message no matter what I input into Scanner. The code: The output: Answer Like Namandeep_Kaur comment said, your for loop condition is incorrect. You want it to be i < 10
How to fully print outer loop before inner loop (Java)
My goal is to print a chart that displays “enemy” number, x and y coordinates, then their distance in respect to the other “enemies”, but with my following nested loop below, the enemy number, and coordinates are reversed with the distance numbers. I’ve tried adjusting the position of the codes, but they don’t seem to fix the issue. Answer