Hey everyone looking for help for these questions. 1. Write the statement to acc
ID: 3771721 • Letter: H
Question
Hey everyone looking for help for these questions.
1. Write the statement to access the 8th element of the array defined below?
Integer [] priceList = new Integer [10];
2. Add the variable called input to the ArrayList declared below.
private static ArrayList<Integer> floors = new ArrayList<>();
4.Given the following array declaration, what statement would print out Blueberry – 3.14 to the screen?
double [] myNumbers = new double[]{1.23, 3.14, 5.18, 82, 2.56};
String [] myPi = new String[]{"Strawberry", "Lemon", "Blueberry", "Apple", "Pumpkin"};
5.Assume that this code fragment compiles and runs. What is its output? As always, be precise when showing your output.
public static void main(String [] args)
{
int x = 3;
int xf = 0;
if (x == 0 || x == 1)
{
xf = 1;
}
else
{
xf = 1;
for (int i=2; i<=x; i++)
{
xf *= i;
}
}
System.out.println("Results are: " + xf);
}
6.Assume that this program compiles and runs. Assume that the user enters 5 6 (separated by a space) for input. What is the output? As always, be precise when showing your output.
import java.util.Scanner;
public class TryCatchQuestion
{
public static void main(String [] args)
{
Scanner stdIn = new Scanner(System.in);
System.out.println("Please enter 2 numbers seperated by a space");
try
{
System.out.println("Output: " + stdIn.nextInt() / stdIn.nextInt());
}
catch (NumberFormatException e)
{
System.out.println("Number Format Exception");
}
catch (ArithmeticException e)
{
System.out.println("Division by zero");
}
catch (Exception e)
{
System.out.println("Other Exception");
}
}//end main
}//end TryCatchQuestion
7. Assume that this program compiles and runs. Assume that the user enters 5 0 (separated by a space) for input. What is the output? As always, be precise when showing your output.
import java.util.Scanner;
public class TryCatchQuestion
{
public static void main(String [] args)
{
Scanner stdIn = new Scanner(System.in);
System.out.println("Please enter 2 numbers seperated by a space");
try
{
System.out.println("Output: " + stdIn.nextInt() / stdIn.nextInt());
}
catch (NumberFormatException e)
{
System.out.println("Number Format Exception");
}
catch (ArithmeticException e)
{
System.out.println("Division by zero");
}
catch (Exception e)
{
System.out.println("Other Exception");
}
}//end main
}//end TryCatchQuestion
8.Assume that this program compiles and runs. Assume that the user enters 5 six (separated by a space) for input. What is the output? As always, be precise when showing your output.
import java.util.Scanner;
public class TryCatchQuestion
{
public static void main(String [] args)
{
Scanner stdIn = new Scanner(System.in);
System.out.println("Please enter 2 numbers seperated by a space");
try
{
System.out.println("Output: " + stdIn.nextInt() / stdIn.nextInt());
}
catch (NumberFormatException e)
{
System.out.println("Number Format Exception");
}
catch (ArithmeticException e)
{
System.out.println("Division by zero");
}
catch (Exception e)
{
System.out.println("Other Exception");
}
}//end main
}//end TryCatchQuestionAssume that this program compiles and runs. Assume that the user enters 5 six (separated by a space) for input. What is the output? As always, be precise when showing your output.
import java.util.Scanner;
public class TryCatchQuestion
{
public static void main(String [] args)
{
Scanner stdIn = new Scanner(System.in);
System.out.println("Please enter 2 numbers seperated by a space");
try
{
System.out.println("Output: " + stdIn.nextInt() / stdIn.nextInt());
}
catch (NumberFormatException e)
{
System.out.println("Number Format Exception");
}
catch (ArithmeticException e)
{
System.out.println("Division by zero");
}
catch (Exception e)
{
System.out.println("Other Exception");
}
}//end main
}//end TryCatchQuestion
Explanation / Answer
a) System.out.println(pricelist[7])
b) int[ ] input = new int[0]
c) System.out.println{(myPi[2])"-"(myNumbers[1])}