Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program 21:
- package com.Suarez;
- /*
- Xander Fermier
- 1/22/19
- this programs generates random numbers until it rolls five and then terminates
- */
- import java.util.*;
- public class RandomGenerateFive {
- public static void main(String[]args)
- {
- Random rand = new Random();
- int i;
- do {
- i = rand.nextInt(5) + 3;
- if (i == 5)
- {
- break;
- }
- System.out.println(i);
- }
- while (i !=5);
- }
- }
- Program 22:
- package com.Suarez;
- /*
- Xander Fermier
- 1/22/19
- this program takes in a starting value and then values afterwards and if the secondary values are > the starting value it will print them. inputting 20
- terminates the program
- */
- import java.util.*;
- public class UserIntegerOutput {
- public static void main(String []args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Give me the lowest number");
- int firstNum = scan.nextInt();
- if (firstNum == 20)
- {
- System.out.println("That number doesn't exist right now. Do another number");
- }
- int nextNum;
- do {
- System.out.println("Give me your next number to compare");
- nextNum = scan.nextInt();
- if (nextNum == 20)
- {
- break;
- }
- if (nextNum >= firstNum)
- {
- System.out.println(nextNum);
- }
- }
- while(nextNum != 20);
- }
- }
- program 23:
- package com.Suarez;
- /*
- Xander Fermier
- 1/22/19
- this program asks the user for numbers and then gets the sum of all of the numbers inputted and if the user enter -1 the program stops
- */
- import java.util.*;
- public class UserInputAdd {
- public static void main(String[]args)
- {
- Scanner scan = new Scanner(System.in);
- System.out.println("Give me your starting number. Input \"-1\" to stop.");
- int startnum = scan.nextInt();
- int addnum;
- int totalnum = startnum;
- do {
- System.out.println("Give me the next number to add");
- addnum = scan.nextInt();
- startnum += addnum;
- if (addnum == -1)
- {
- break;
- }
- totalnum += addnum;
- System.out.println("Current sum is " + totalnum);
- }
- while(addnum != -1);
- System.out.println("The end sum is " + totalnum);
- }
- }
- program 24:
- package com.Suarez;
- /*
- Xander Fermier
- 1/22/19
- this programs uses a while loop to add the first four multiples of seven
- */
- import java.util.*;
- public class FirstFourMultiplesOfSeven {
- public static void main(String[]args)
- {
- int sum = 0;
- int countMultiplesOf7=7;
- int count = 1;
- while (count <= 4)
- {
- //sum += countMultiplesOf7;
- //countMultiplesOf7 += 7;
- sum += (countMultiplesOf7*count);
- count ++;
- }
- System.out.println(sum);
- /*
- The smarter way to do this is to make a for loop. That way you could have the max attached to a number the user
- puts int more easily and it would just make more sense all around to use a for loop.
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement