Java array help. Not sure how to start off with this. Will rate! Getting Started
ID: 3558862 • Letter: J
Question
Java array help. Not sure how to start off with this. Will rate!
Getting Started
Create a class called
Lab7. Use the same setup for setting up your class and main method as you
did for the previous assignments. Be sure to name your file
Lab7.java.
Hints
?
(Page 250) An array will be used in this program.
?
The lecture and code example videos are also good references for this lab.
Task Overview
The overall goal of this lab is to allow the user to enter five integers into an array. The program
will then print out each of these integers + 1.
Part 1: Initial Setup
The following needs to be done for the initial setup:
?
Create a Scanner object
Explanation / Answer
import java.util.Scanner;
public class Array {
public static void main(String[] args) {
int SIZE=5;
int i;
int []arr= new int[SIZE];
System.out.println("enter elements");
for(i=0;i<5;i++){
Scanner sc=new Scanner(System.in);
arr[i]=sc.nextInt();
}
for(i=0;i<5;i++){
arr[i]=arr[i]+1;
System.out.println(arr[i]);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.