ok so what i am trying to do is create a random int and save it into an
arraylist and sum up the contents of the array list. then ask the user if they would like to roll again. any point in the right direction would be appreciated. so far this is what i have got:

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

public class testfp {
	public static void main(String[] args) 
		throws FileNotFoundException {
		
		Scanner user = new Scanner(System.in);	
			Random r = new Random();
								
		System.out.println("Welcome to the exciting game of 36 ");	
		int roll;
		int sum;
		
		ArrayList<Integer> list = new ArrayList<Integer>();		
		
			roll = r.nextInt(6) + 1;
			list.add(roll);
			sum = 0;
			
		for(int n : list){
			sum += n;
		}
		System.out.println("You rolled a: " + roll);
		System.out.println("Your sum is now: " + sum);
		System.out.println("would you like to roll again? Y/N");
		
			
	}	
}

this is what the output is

----jGRASP exec: java testfp

Welcome to the exciting game of 36
You rolled a: 5
Your sum is now: 5
would you like to roll again? Y/N

----jGRASP: operation complete.

i do not which loop to use or where to use it

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

public class testfp {
	public static void main(String[] args) 
		throws FileNotFoundException {
		
		Scanner user = new Scanner(System.in);	
			Random r = new Random();
								
		System.out.println("Welcome to the exciting game of 36 ");
		
		int roll;
		int sum;
		
		ArrayList<Integer> list = new ArrayList<Integer>();		
		
			roll = r.nextInt(6) + 1;
			list.add(roll);
			sum = 0;
			
		for(int n : list){
			sum += n;
		}
		System.out.println("You rolled a: " + roll);
		System.out.println("Your sum is now: " + sum);
		System.out.println("would you like to roll again? Y/N");
	
		String yn = user.next();
		
		String ys="Y";
		String no="N";
		do{
			if(yn.equals(no)){
				//will compare it to computer's sum

			}else if(yn.equals(ys)){
				// roll again

			}
		}while ((yn.equals(no) || yn.equals(ys)));		
				System.out.println("invalid entry");
				System.out.println("would you like to roll again? Y/N");
			 	user.next();
			
			
	}	
}

the problem is if someone put in something other then Y or N it will prompt again but then if they put in something wrong the next time it ends the program.
ie:

----jGRASP exec: java testfp

Welcome to the exciting game of 36
You rolled a: 4
Your sum is now: 4
would you like to roll again? Y/N
u
invalid entry
would you like to roll again? Y/N
i

----jGRASP: operation complete.

can u explain me wat u r trying to do ..

ok so what i am trying to do is create a random int and save it into an
arraylist and sum up the contents of the array list. then ask the user if they would like to roll again. any point in the right direction would be appreciated. so far this is what i have got:

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

public class testfp {
	public static void main(String[] args) 
		throws FileNotFoundException {
		
		Scanner user = new Scanner(System.in);	
			Random r = new Random();
								
		System.out.println("Welcome to the exciting game of 36 ");	
		int roll;
		int sum;
		
		ArrayList<Integer> list = new ArrayList<Integer>();		
		
			roll = r.nextInt(6) + 1;
			list.add(roll);
			sum = 0;
			
		for(int n : list){
			sum += n;
		}
		System.out.println("You rolled a: " + roll);
		System.out.println("Your sum is now: " + sum);
		System.out.println("would you like to roll again? Y/N");
		
			
	}	
}

this is what the output is

----jGRASP exec: java testfp

Welcome to the exciting game of 36
You rolled a: 5
Your sum is now: 5
would you like to roll again? Y/N

----jGRASP: operation complete.

i do not which loop to use or where to use it

i'm making a dice game called 36 it's like the card game 21 but with dice. the part i'm working on right now rolls die and prints the amount to an arraylist where it will be summed up and then compared to either the computer's sum or another players sum haven't decided which yet.
but i am working on getting the program to loop rolling the die after the user decides to roll again.

the part i am stuck on right now is trying to add another random int (die roll) to the arraylist when the user rolls the die again
any ideas??

This article has been dead for over six months. Start a new discussion instead.