Slot Machine 2.0 Hackerrank Solution

Hackerrank

  1. Slot Machine 2.0 Hackerrank Solution Software
  2. Slot Machine 2.0 Hackerrank Solutions
  1. In order to start this puzzle, Junpei must have a coin bag in his possession and use it on the middle machine. Although it may look like he needed to get the same reels in a row to win by guessing using luck and timing, the buttons on the machine are really there to be pressed in a certain order shown by the secret code mentioned earlier.
  2. The manager of a casino would like to add a new type of slot machine game to the casino. Given below are the probability distributions for her top four choices. The values of the random variable are the amounts the casino would either gain (positive values) or have to pay out (negative values).

I've got everything finished for the program, but it's telling me that the 'else if' won't work because I don't have an 'if' but I have the 'if' right above it. I tried making them all 'if' to see.

Couldn’t get formatting on here so make sure to format 🙂

Welcome to Java

public class Solution {

Slot Machine 2.0 Hackerrank Solution Software

public static void main(String []argv)
{
//Write your solution here.
System.out.println(“Hello World.”);
System.out.println(“Hello Java.”);
}

}

Java Stdin and Stdout I

import java.util.*;

public class Solution {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}

Java If-Else

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {

Slot Machine 2.0 Hackerrank Solutions

Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String ans=””;
if((n%21 || ((n>5) && (n<21)))){
ans = “Weird”;
}
else{

ans = “Not Weird”;

}
System.out.println(ans);

}
}

Java Stdin and Stdout II

import java.util.Scanner;

public class Solution {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int x=sc.nextInt();
double y=sc.nextDouble();
sc.nextLine();
String s=sc.nextLine();

System.out.println(“String: “+s);
System.out.println(“Double: “+y);
System.out.println(“Int: “+x);
}
}

Java Output Formatting

import java.util.Scanner;

public class Solution {

public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println(“”);
for(int i=0;i<3;i++)
{
String s1=sc.next();
int x=sc.nextInt();
System.out.printf(“%-15s%03dn”,s1, x);

}
System.out.println(“”);

}
}

Java Loops 1

import java.io.*;
import java.util.*;

public class Solution {

public static void main(String[] args) {

/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 1; i <= 10; i++) {
int sum = n * i;
System.out.println(n + ” x ” + i + ” = ” + sum);
}

}
}

Java Loops 2

import java.util.*;
import java.io.*;

public class Solution {
public static void main(String[] args) {
int x=0;
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i=0;i<t;i++){
// Store values
int a = sc.nextInt();
int b = sc.nextInt();
int n = sc.nextInt();
// x = a
x=x+a;
for(int j=0;j<n;j++){
// Formula: a+2^0*b+2^1*b+..
x = x+(int)(Math.pow(2,j))*b;
System.out.print(x+” “);
}
// Make x = 0 so new values go through same operation
x=0;
System.out.println();
}
}
}