My Java issues: 1) I don't know how to use Scanner to loop if the user enters an integer that's out of range. 2) When the range is correct, the output includes 0 instead of the 2 integers I entered 3)...




My Java issues:


1) I don't know how to use Scanner to loop if the user enters an integer that's out of range.


2) When the range is correct, the output includes 0 instead of the 2 integers I entered


3) After creating the array's element number:

System.out.print("How many numbers do you want to enter?");




int num=scnr.nextInt();


I created a loop prompting once instead of prompting each time for a value because I don't know how to individually store each prompt's value into an array.



Java code:


import java.util.Scanner;


public class Main {
public static void title(String name) {
System.out.println("CIS - Assignment  - " +name);
}


//later on:
//Create public class for average, high, low, above average, equal to average, below average, std. dev.
//public class temp(int a, int b, int c) {




public static void main(String[] args) {
// write your code here
Scanner scnr =new Scanner(System.in);
int i=0;
int j=0;


System.out.print("How many numbers do you want to enter?");
int num=scnr.nextInt();
int aList[]=new int[num]; //store array from user's input
System.out.println("Please enter " +num+ " integer from 1 to 35.");
for (j = 0; j < alist.length;="">
aList[i] = scnr.nextInt();
if (aList[i] >= 1 && aList[i] <=35)>
for (i = 0; i < alist.length;="">
System.out.println(aList[i]);
}
if (aList[i] > 35) {
System.out.println("Please enter within the range of 1-35 or this cycle will loop forever");
scnr.nextInt();
i++;
}
}
}





My Errors when an integer is out of range using IntelliJ:


How many numbers do you want to enter? 2
Please enter 2 integers from 1 to 35.
30

90
Please enter within the range of 1-35 or this cycle will loop forever
21
Please enter within the range of 1-35 or this cycle will loop forever
0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at com.company.Main.main(Main.java:41)


Process finished with exit code 1




My Errors when an integer is within range using IntelliJ:


How many numbers do you want to enter? 2
Please enter 2 integers from 1 to 35.
20
30
30
0
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at com.company.Main.main(Main.java:36)


Process finished with exit code 1





Problem to Solve:



  1. The program will input from 1 to 35 (inclusive) Fahrenheit temperatures from the user. You must first ask them to enter the number of temperatures that they will be typing in. If the value entered is not between 1 and 35, you need to display a message informing the user that the value they entered is out of range and make them re-input until they provide an acceptable value. Prompt every input.

  2. The Fahrenheit values are doubles and must range between -150.0 and 350.0


(inclusive.) If an out-of-range temperature is entered, you must display a


message informing the user as such and have them re-input until an in-range


value is entered.


Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here