How to arrange the result neatly?
public class LabTest {
public static void main(String[] args) {
String[] state= {"Johor", "Kedah","Kelantan","Melaka","Negeri
Sembilan","Pahang","Perak","Perlis","Pulau
Pinang","Sabah","Sarawak","Selangor","Terengganu","Wilayah
Persekutuan Labuan","Wilayah Persekutuan Kuala Lumpur"};
int [] rainfall=
{1133,1312,1699,1220,1450,1596,1350,1189,1347,1987,1999,1125,1789,1980,1374};
int temp;
String tempN;
for (int i=0;i<rainfall.length;i++){
for (int j=0;j<rainfall.length;j++){
if (rainfall[i]>rainfall[j]){
temp=rainfall[i];
rainfall[i]=rainfall[j];
rainfall[j]=temp;
tempN=state[i];
state[i]=state[j];
state[j]=tempN;
}
}
}
for (int i=0;i<rainfall.length;i++){
System.out.print(state[i] + "\t");
}
System.out.println("");
for (int i=0;i<rainfall.length;i++){
System.out.print(rainfall[i] + "\t");
}
}
}

#source code:
public class LabTest {
public static void main(String[] args) {
String[] state= {"Johor", "Kedah","Kelantan","Melaka","Negeri
Sembilan","Pahang","Perak","Perlis","Pulau
Pinang","Sabah","Sarawak","Selangor","Terengganu","Wilayah
Persekutuan Labuan","Wilayah Persekutuan Kuala Lumpur"};
int [] rainfall=
{1133,1312,1699,1220,1450,1596,1350,1189,1347,1987,1999,1125,1789,1980,1374};
int temp;
String tempN;
for (int i=0;i<rainfall.length;i++){
for (int j=0;j<rainfall.length;j++){
if (rainfall[i]>rainfall[j]){
temp=rainfall[i];
rainfall[i]=rainfall[j];
rainfall[j]=temp;
tempN=state[i];
state[i]=state[j];
state[j]=tempN;
}
}
}
for (int i=0;i<rainfall.length;i++){
System.out.printf("%-30.30s %-30.30s%n",
state[i],rainfall[i]);
System.out.println("");
}
}
}
#output:

#if you want display horizontal way just comment below...if you like give thumbs up....
How to arrange the result neatly? public class LabTest { public static void main(String[] args) {...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
Draw a flowchart for this program public class InsertionSort { public static void main(String a[]) { int[] array = {7, 1, 3, 2, 42, 76, 9}; insertionSort(array); } public static int[] insertionSort(int[] input) { int temp; for (int i = 1; i < input.length; i++) { for (int j = i; j > 0; j--) { if (input[j] < input[j - 1]) { temp = input[j]; input[j] = input[j - 1]; input[j - 1] = temp; } } display(input, i);...
import java.util.Arrays; public class lab { public static void main(String args[]) { int arr[] = {10, 7, 8, 9, 1, 5,6,7}; int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1}; int arr3[] = {1, 3, 5, 3, 2, 6, 20}; quicksort(arr,0,arr.length-1); quicksort(arr2,0,arr2.length-1); quicksort(arr3,0,arr3.length-1); System.out.println(Arrays.toString(arr)); System.out.println(Arrays.toString(arr2)); System.out.println(Arrays.toString(arr3)); } private static int partition(int[] items,int low, int high) { int i=0; int j=0;...
Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn); else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...
(Java) the question is comments under public static void main(String[] args) { for(int i =1; i<=5; i++) { for(int j=1; j<=i; j++) { System.out.print("* "); } System.out.println(""); // } for(int i=1; i<=4;i++) { for(int j=4; j>=i; j--) // j>=i means each row has * of columns, so first row ****, second row ***, and so on ...
What is the Java output? Part One: class Driver { public static void main(String[] args) { int a = 5; int b = 3; if (a < b || a * 2 < b) System.out.print(a - b); System.out.print(b + a); } } Part Two: class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a < b) if (a * 2 < b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } }
package array; public class Test { static int[] data = (0,1,2,3,4,5,6,7,8); public static void main (String[] a) { for ( int i = 0;i<data.length; i++) { if(i %3 == 0) { System.out.print("A"); System.out.print(data[i]); System.out.print(" "); } } I need an explanation of what this code is doing ? is there anything wrong with it }}
import java.util.Scanner; public class Chpt7_Project { public static void bubbleSort(int[] list) { int temp; for (int i = list.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (list[j] > list[j + 1]) { temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } ...
c) public class Test { public static void main(String[] args) { T t1 = new T(); T t2 = new T(); System.out.println("t1's i = " + t1.i + " and j = " + t1.j); System.out.println("t2's i = " + t2.i + " and j = " + t2.j); } } class T { static int i = 0; int j = 0; T() { i++; j = 1; } } Why is t1's i = 2 ? It should be...
Review the following code: public class Looping { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { System.out.println(i + " x " + j + " = " + (i * j)); } } } } What is the output from the code above? Replace this text with your solution What happens if you change the...