Answer:
The code will get stuck in an infinite loop.
Explanation:
Since val is decreasing by 1 each time it meets the criteria of being smaller than 10, your code will get stuck in an infinite loop since val will always be smaller than 10.
Hope this helps :)
The only way without a while loop and no method I can think of is use switch with every possible variation of the four digit binary which is 15.
Here is the starter code:
import java.util.Scanner;
public class MyClass {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int digit = sc.nextInt();
switch(digit) {
case 0000:
System.out.println("0");
break;
case 0001:
System.out.println("1");
break;
case 0010:
System.out.println("2");
break;
case 0011:
System.out.println("3");
break;
case 0100:
System.out.println("4");
break;
… (fill in other cases)
}
}
}
Use this link: https://www.electronics-tutorials.ws/binary/bin_3.html
There might be a better way, but without loops or methods this is all I got.
It would be either one i belive... but i would choose C if your talking about google
Answer:
import numpy as np
def genRandomVect():
arr = np.random.choice(range(100),size=(50,),replace=False)
return arr
print("Random 1D numpy array where each element is an integer sampled from: [0, 100) ")
print( genRandomVect() )
Explanation:
- Create a function to create a numpy array with random integers in range[0,100) with no duplicates
- Use the random.choice to select random values from range[0,100) and size attribute to take the size of the required array
.
- Finally return the numpy array.
Answer:
The pseudocode is as follows
1. Input Steps
2. Input Day
3. Miles = Steps/2000
4. Calories = 65 * Miles
5. Print Calories
6. Stop
Explanation:
This line gets the number of steps for the day
1. Input Steps
This line gets the current day
2. Input Day
The line calculates number of miles
3. Miles = Steps/2000
This line calculates the calories lost
4. Calories = 65 * Miles
This line prints the calories lost
5. Print Calories
The pseudocode ends here
6. Stop