Skip to main content
ยท2 min read

The How-Tos When It Comes To Defining, Assigning, And Printing A Java Array

How to define, assign, and print an array using Java. ๐Ÿ”ƒ Defining an array character type of a size 3 called arraychar array = new char10Ask user to enter 10 ch

The How-Tos When It Comes To Defining, Assigning, And Printing A Java Array

How to define, assign, and print an array using Java. ๐Ÿ”ƒ

Defining an array (character type) of a size 3 called arraychar [] array = new char[10]Ask user to enter 10 characters and assign each of the characters into the arrayfor (int i = 0; i < array.length; i++)

array[i] = keyboard.next().charAt(0);Use the data in array to reverse a list called reverse so that the first element in the list called array is the last element in reversefor (int i = 0; i < array.length; i++)

reverse[reverse.length โ€“ i] = array[i];Write the first use way to use for-loop to print out all elements in the list called reversefor (int i = 0; i < reverse.length; i++)

System.out.print(reverse[i] + " " );Write the second use way to use for-loop to print out all elements in the list called reversefor (char value : reverse)

System.out.print(value + " ");Define a 3 by 4 floating point values array, called scoresdouble [][] scores = new double [3][4];Assign the value for each cell in the array called scores to columnIndex * 20 / rowIndexfor (int row = 0; row < scores.length; row++)

for (int col = 0; col < scores[row].length; col++)

scores[row][col] = col * 20 / (double) row;Print all the values in the array called scoresfor (int row = 0; row < scores.length; row++) {

for (int col = 0; col < scores[row].length; col++)

System.out.print (scores[row][col] + "\t");

System.out.println();

}Write a findMax method which finds the maximum value in the data stored in scoresstatic double findMax(double [][] scores) {

double max = scores[0][0];

for (int row = 0; row < scores.length; row++)

for (int col = 0; col < scores[row].length; col++)

if (scores[row][col] > max)

max = myScores[row][col];

return max;

}


Tags ๐Ÿท๏ธ

Stay in the loop

๐Ÿฆ„ The Unicorn Engineer โœจ

Personal and career learnings, advice, collaboration opportunities, and more. Delivered straight to your inbox.

No spam. Unsubscribe anytime.

Keep Reading

Related Posts

The Day After Calculus Ended
ยท2 min read

The Day After Calculus Ended

Exploring blogging applications. Honestly, the best blogging utility would be a combination of Bywordhttps://bywordapp.com/โ€˜s simple UI, publishing, and exporti

Blog
Speech - Robotics In The Workforce
ยท6 min read

Speech - Robotics In The Workforce

The idea of robots taking over the economy. This was a speech I made for my Oral Communications class regarding the idea of technology robots taking over the ec

Blog
Integrating Your School Emails With Airmail
ยท4 min read

Integrating Your School Emails With Airmail

So in case you haven't heard of it yet, Don't Starve is this awesome Indie game. So I have 4 different email accounts, my personal one, and then 3 other ones fo

Blog

Stay in the Loop โœ๐Ÿฝ

I share thoughts on engineering, career growth, and the tech industry. Follow along for more.