Skip to main content

All Questions

Tagged with
-1 votes
2 answers
51 views

How to find each word in a 2D array from a specific ch

I'm new to Java and I'm trying to work this question out: Write another method in the class (a suitable name for this method would be findChar). This method should take a char and a 2 dimensional ...
Matthew Wallbridge's user avatar
-1 votes
2 answers
49 views

Error while building a program which should output assigned domino tiles for each player in Java

So, I am a total beginner in Java. I need a program that takes a number of players as an input. Then assuming there are 91 domino tiles each with two squares with dots ranging from 0 to 12 in each ...
PabloSaint's user avatar
0 votes
1 answer
78 views

Java's advanced for loop not inputting captured values from nextInt properly

After initializing an array and using the For-Each Loop to capture 2 input values and update in the array, printing the values out results only in the last integer input showing, a zero. int[] ...
Ken Kiarie's user avatar
0 votes
1 answer
47 views

iText 7, first item in my loop doesn't get formatted. Any idea why?

When I run my loop, it is supposed to format "res.position" ,and it does for every iteration of the loop except for the first one. for(int i = 0; i < res.numJobs; i++) { document.add(...
Om Bakhshi's user avatar
0 votes
2 answers
76 views

For loop condition not working as per expectations

I am writing a code in this code I have to find the minimum steps which can take me from index 0 to index n-1. nums[i] represent the maximum jump I can take from ith index. (Reference leetcode Q45 ...
jainyashit's user avatar
-1 votes
1 answer
205 views

How to populate an array automatic with an user` input?

i m writing a code as homework, the task is to create a code, where the user give a number (for example 4 ) and the output will be all the number from 4 ( the users input ) till the length of array (...
Reffert's user avatar
1 vote
2 answers
444 views

Problem with counting Battleship sunken ships/ships (Java)

So I am making a method for a battleship game which consists of ships ranging from 2-5 squares horizontally on a 10x10 grid in Java. This method is to count the number of sunken ships on the grid ...
Danish's user avatar
  • 21
-4 votes
2 answers
113 views

How do I use a for loop inside a method with an array parameter? [closed]

I want to start and preference that I am still new to this and learning. I'm trying to figure out how to use a for loop for this assignment. Hopefully I can get some help :) This is the code. package ...
Prago's user avatar
  • 37
2 votes
2 answers
46 views

how to print an array forward and backward based on boolean flag true/false using single for loop in java?

Arr = {"apple" , "orange" , "pineapple"}; If (boolean)flag = true : o/p - pineapple orange apple Else o/p - apple orange pineapple I tried using while, how to implement ...
Suravi's user avatar
  • 29
-1 votes
1 answer
52 views

I want to make a for loop that asks and answers its questions but i think i want 2 variables in the for llop and idk how

public class Main { public static void main(String[] args) { String[] cars = new String[3]; cars[0] = "bmw"; cars[1] = "tesla"; cars[2] = &...
NotChris's user avatar
0 votes
1 answer
126 views

Using an if else statement with a string condition inside of a nested for loop

I am doing an exercise in which i have to create a trivia game, i need 5 questions and 5 answers and to store them using arrays, which i have managed to do just fine so far, then i have to create at ...
prinathebanana's user avatar
1 vote
2 answers
105 views

The value of the variable "m" is not getting updated when i am trying to print the string which is declared outside the loop

This is the code I'm trying to execute: class test { public static void main(String[] args) { int num = 5; var i = 0; int m = 0; String[] m_id = {"1","2","...
SAMSON JACK's user avatar
2 votes
3 answers
116 views

Filling 2D array diagonally

I've been trying to get a 10x10 2D array filled diagonally as in the image below for a couple hours now, but after checking every possible way to use rows and columns I still can't seem to identify my ...
blackburrow112's user avatar
0 votes
0 answers
53 views

In Java, how do I check if a specific element appears in an array? [duplicate]

Please bear with me, I am very new to Java. I have created an array that is created from two text files using File Reader when the program is run, I need to check if an element in the list is a ...
EkatS's user avatar
  • 11
1 vote
2 answers
60 views

Initialization, conditions, and afterthought of for-looping to add variable value each time the arraylist size reach certain value

I want to make a program that consist of 1 arraylist and 1 variable. So, every time the arraylist's size 59, 118, 177,..... (added by 59), will add the variable by 1. int a = 0; ArrayList<String>...
Abisay's user avatar
  • 47

15 30 50 per page
1
2 3 4 5
118