Internet Question Interview Question


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.Practice;

public class DiceGameCC {
	
	static int sum(int arr[]){
		int total =0;
		int n = arr.length;
		for(int i=0;i<n;i++){
			total = total+arr[i];
		}
		return total;
	}
	
	public static int randomNum(int min, int max){
		
		int randomNum = min + (int) (Math.random() * (max - min)+1);
		//System.out.println("Num  "+randomNum);
	    return randomNum;
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		System.out.println("Player 1 turn : ");
		int player1[] = new int[10];
		for(int i=0;i<10;i++){
			player1[i] = randomNum(0,6);
			System.out.print(player1[i] +" ");
		}
		System.out.println(" ");
		
		System.out.println("Player 2 turn : ");
		int player2[] = new int[10];
		for(int i=0;i<10;i++){
			player2[i] = randomNum(0,6);
			System.out.print(player2[i]+" ");
		}
		System.out.println(" ");
		
		if(sum(player1) > sum(player2)){
			System.out.println("Player 1 wins with score : "+(sum(player1)));
		}
		else
			System.out.println("Player 2 wins with Score : "+sum(player2));
	}

}

- Sameer August 09, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Arrays;


public class diceExample {

/**
* @param args
*/
public static void main(String[] args) {
int [] player1 = new int[10];
int [] player2 = new int[10];
int player1Sum=0;
int player2Sum=0;
System.out.println("first will throw dice 10 time");

for(int i=0;i<9;i++){
int value=1+(int)(Math.random()*6);
player1[i]=value;
player1Sum=player1Sum+value;
}
System.out.println("first will throw dice 10 time");

for(int i=0;i<9;i++){
int value=1+(int)(Math.random()*6);
player2[i]=value;
player2Sum=player2Sum+value;
}
System.out.println("first Array");
for (int i = 0; i < player1.length; i++) {
System.out.println(player1[i]);
}
System.out.println("second Array");
for (int i = 0; i < player2.length; i++) {
System.out.println(player2[i]);
}
System.out.println(player1Sum);
System.out.println(player2Sum);
}

}

- Anonymous September 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Arrays;


public class diceExample {

/**
* @param args
*/
public static void main(String[] args) {
int [] player1 = new int[10];
int [] player2 = new int[10];
int player1Sum=0;
int player2Sum=0;
System.out.println("first will throw dice 10 time");

for(int i=0;i<9;i++){
int value=1+(int)(Math.random()*6);
player1[i]=value;
player1Sum=player1Sum+value;
}
System.out.println("first will throw dice 10 time");

for(int i=0;i<9;i++){
int value=1+(int)(Math.random()*6);
player2[i]=value;
player2Sum=player2Sum+value;
}
System.out.println("first Array");
for (int i = 0; i < player1.length; i++) {
System.out.println(player1[i]);
}
System.out.println("second Array");
for (int i = 0; i < player2.length; i++) {
System.out.println(player2[i]);
}
System.out.println(player1Sum);
System.out.println(player2Sum);
}

}

- jpant September 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is this the first homework for Introduction to Programming course in high school?

- Anonymous October 17, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More