Skip to content
Advertisement

Tag: loops

confused about java looping

I just started learning programming and java is my first language. I’ve come across an exercise involving for loop, I’d like to know how the result is found: the output is: 17 I know this is a silly basic question but I really need to understand how the result is 17. Answer In your loop : the i starts at

Limit login attempt in Java

I am trying to limit the maximum login attempts to 3. However, my code below uses all the attempts before the user can get a chance to press the login button again. How would I fix this? Answer Whenever, the executeLogin() will be invoked, the previous value of totalAttempts will be erased and it will be again initialized to 3.

Draw an ASCII diamond in a frame

I am trying to draw out a diamond in a frame. I figured my way through the top half, but when I come to the 2nd half I had attempted to invert the loops and problems came up. I played around switching operators just to see the result, but still nothing works. Please help. What am I not seeing. Answer

Given three integers a, b, and n,output the following series: a+20b,a+20b+21b,……,a+20b+21b+…+2n−1ba+20b,a+20b+21b,……,a+20b+21b+…+2n−1b

Constraints: 0≤t≤500 0≤a,b≤50 1≤n≤15 Sample Input: Sample Output This works in my IDE but when I try it in an online editor in hackerrank.com it throws an exception: Exception in thread “main” java.util.NoSuchElementException: No line foundat java.util.Scanner.nextLine(Scanner.java:1585)at Solution.main(Solution.java:24) Please explain why this happens.Thanks! Answer Remove iput.nextLine(); on line 24 so that no extra reading will happen.

Java, comparing a Linked List to an Array

Working on a Java program that will read in two different passages, convert both strings to arrays of strings for each word, and then String One to a linked list, which will promptly be sorted into alphabetical order. After the list has been sorted, I get confused. I have a for loop written to get the length of array2 to

Advertisement