A. Introduction
for loops allows us to repeat some operations on large amount of data. However, we can't store these data in hundreds of variables. Instead, we use arrays to create hundreds or thousands of variables in one statement.
B. See details at 6.1
C. Try
1. Without using a standard library function, how will you find the max/min number in an int array? How to sort an array?
R7.3 Nothing happens. The code doesn't get run through.
R7.2 a. The location of an item in an array b. integer values between 0 and the array's length - 1 c. A bounds error is a runtime error
R7.4 I didn't know how to this.
R7.1 https://repl.it/@DaveyYu/Homework, g.https://repl.it/@DaveyYu/2nd-Homework
R7.2 a out of bounds error is that there is no number in that slot. If you need example here-https://repl.it/@DaveyYu/RIP-out-of-bounds-error?language=java
R7.3 Nothing. The code just stops running.
R7.4 https://repl.it/@DaveyYu/Reverse-order
R7.4: https://repl.it/@Brainseater905/MountainousNoxiousNet Please look at it, because there's a problem with the "static"
R7.1: https://repl.it/@Brainseater905/SecretNauticalCoding
import java.io.*;
import java.util.Scanner;
class chmod {
public static String getBinary(int input){
int binary[] = new int[3];
int total = 0;
int count = 0;
for(int i=2; i>=0; i--){
if(total+Math.pow(2,i)<=input){
binary[count]=1;
total += Math.pow(2,i);
}
else{binary[count]=0;}
count++;
}
String output = "";
for(int i=0; i<3; i++){
output = output + binary[i];
}
return output;
}
public static String getPermissions(String Binary){
String permissions = "";
for(int i=0; i<3; i++){
if(Binary.charAt(i)== "1".charAt(0)){
switch(i){
case 0: permissions = permissions + "r"; break;
case 1: permissions = permissions + "w"; break;
case 2: permissions = permissions + "x"; break;
}
}
else{permissions = permissions + "-";}
}
return permissions;
}
public static void main(String[] args) throws IOException{
Scanner Jordan = new Scanner(new FileReader("data/input.txt"));
for(int i=0; i<5; i++){
String input = Jordan.nextLine();
String inputs[] = input.split(", ");
for(int j=0; j<3; j++){
String output=getBinary(Integer.parseInt(inputs[j]));
System.out.print(output + " ");
}
System.out.print("and ");
for(int j=0; j<3; j++){
String output=getPermissions(getBinary(Integer.parseInt(inputs[j])));
System.out.print(output + " ");
}
System.out.println();
}
}
}
R7.2
a. The index of a array is a number beginning from 0.
b. legal index values is 0 to the first three numbers
c. a bounds error is when a there is a Runtime Exception.
R7.3
https://repl.it/@Brainseater905/PrestigiousPleasedScope
Me and Davey is confused on R7.4 and R7.1. RIP