Question

JAVA IDE NETBEANS Create a program that will prompt the user to enter 20 numbers using...

JAVA IDE NETBEANS

Create a program that will prompt the user to enter 20 numbers using any looping statement. Store it in a 2-dimensional array. Display all the numbers in a table format. Determine which numbers are odd and which numbers are even (include their array index)

need some help with codes

Homework Answers

Answer #1

SOLUTION:

Copy the given code into NetBeans where the project folder's main class is present.

import java.util.*;

public class MyClass {
    public static void main(String args[]) {
        //Svanner is used to read data from User
        Scanner sc = new Scanner(System.in);
        //2d array Declaration
        int[][] num = new int[2][10];
        //Variable Declarations
        int i=0;
        int j=0;
        int k=0;
        // loop to read and store user data into loop
        while(i<20){
            num[j][k]=sc.nextInt();
            k+=1;
            if(i==9){
                j+=1;
                k=0;
            }
            i++;
        }
        // Head of the Table
        System.out.println("-----------------------------------------------");
        System.out.printf("%10s %10s %10s %10s", "Index", "Value", "Even", "Odd");
        System.out.println();
        System.out.println("-----------------------------------------------");
        k=0;
        // Rows of the Table
        for(i=0;i<2;i++){
              for(j=0;j<10;j++){
                  int val=num[i][j];
                  System.out.format("%10s %10s %10s %10s",
                    k++,val,val%2==0,val%2!=0);
            System.out.println();      
              }
          }
        System.out.println("-----------------------------------------------");
    }
}

OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Java program to randomly create an array of 50 double values. Prompt the user...
Write a Java program to randomly create an array of 50 double values. Prompt the user to enter an index and prints the corresponding array value. Include exception handling that prevents the program from terminating if an out of range index is entered by the user. (HINT: The exception thrown will be ArrayIndexOutOfBounds)
Create a simple addition calculator in Java. The program should prompt the user to enter 2...
Create a simple addition calculator in Java. The program should prompt the user to enter 2 integers, then adds the numbers and prints the result. Make sure the program includes appropriate exception handling in case the user does not enter appropriate integer values.
Assembler lanaguage program   The program is to prompt the user to enter a number between 2...
Assembler lanaguage program   The program is to prompt the user to enter a number between 2 and 100. Reject any invalid user inputs and terminate the program if invalid inputs are entered. Print each even number from 2 to the user entered number. Sum these even numbers and print the sum. Print each odd number from 1 to the user entered number. Sum these odd numbers and print the sum. Exit the program when the output is complete. The output...
Design the logic for a program that allows a user to enter 10 numbers, stores the...
Design the logic for a program that allows a user to enter 10 numbers, stores the numbers in an array, then displays all of the numbers, the largest number, and the smallest.  create a solution algorithm using pseudocode  create a flowchart Need to do flowchart in Raptor and can't get it to do min and max or display the array
5) Create a Java program using Scanner: Write a program where you will enter the grade...
5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage. Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math 2) Declare variable total and percentage 3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class 4) Calculate total of...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter...
x86 irvine library assembly code Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”....
A. Write a Java program that asks the user to enter “bus” or “subway” or “walk”. If the user enters “bus” display “$1.00”. If they enter “subway” display “$1.50 and if they enter “walk” display “Free”. B. Write a java program that creates the following two arrays: String[] candidates = {“S Jones”,”Justin Fairfax”,”Clark Duncan”}; int[] votes = {7345,4324,3211}; Write the code that will search the votes array for the candidate with the largest number of votes and prints the name...
JAVA Prompt the user for 10 numbers using a while loop. Create an int variable number....
JAVA Prompt the user for 10 numbers using a while loop. Create an int variable number. You have three additional int variables pos, neg, and zero. Your goal is to determine the number of positive, negative, and zeroes in the list of the ten numbers read in.
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT