I’m currently trying to display a filled asterisk square and a hollow asterisk : Instead, I’m getting this output: I’m not so sure how to make it side by side instead of up and down. Do I have to put the hollow nested loop inside the filled loop or do I have to do something else? Here is my code:
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
How to output an ASCII star patterns in a table format?
I need help with my code issue. I have to write a program that displays a star pattern in a table format. I am not exactly looking for the exact code, I would like to figure it out myself, so any suggestions and tips would be greatly helped. Answer Since you said you don’t want a full solution, here are
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.
indexOf to find all occurrences of a word in a String
I’m trying to use indexOf to find all occurrences of the characters ‘the’ in a sentence. For example, if the sentence were “The other day I went over there”, it should return 3. I am able to do this …
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.
Generating 10 random numbers without duplicate with fundamental techniques
my intend is to use simplest java (array and loops) to generate random numbers without duplicate…but the output turns out to be 10 repeating numbers, and I cannot figure out why. Here is my code: Answer You need to break out of the for loop if either of the conditions are met. This will make YOUR code work but @gonzo
appending arguments to a String
I need to write a simple Java program so as to step through a given string (given from args[]), and receive a println once a certain character (e.g. ‘^’) is encountered. However, I cannot find why I …
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