Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise1 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s = new Scanner(System.in);
- int location = 1, newNum = 0, dig, x, temp;
- System.out.println("Please, Enter a number with at least 5 digits and less than 12 digits? ");
- x = s.nextInt();
- temp = x;
- while (temp > 0) {
- dig = temp % 10; // to get the right most digit
- // if the digit is divisible by 2 then it is even
- if (dig % 2 == 0) {
- newNum = newNum + location * dig;// location set the base 10 of the number
- location = location * 10; // up it by 10 for 100s is 1000
- }
- temp = temp / 10; // cut the last digit of the number
- }
- System.out.println("The number is : " + newNum);
- }
- }
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise2 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s = new Scanner(System.in);
- int location = 1, temp, Num1, Num2, dig1, dig2,newNum=0;
- System.out.println("Please, Enter the first number ? ");
- Num1 = s.nextInt();
- System.out.println("Please, Enter the second number ? ");
- Num2 = s.nextInt();
- temp = Num2;
- while (location > 0)
- {
- dig1 = Num2 % 10; // to get the right most digit of num 2
- newNum = newNum + location * dig1;// location set the base 10 of the number
- location = location * 10; // up it by 10 for 100s is 1000
- dig2 = Num1 % 10;// to get the right most digit of num 1
- newNum = newNum + location * dig2;
- location = location * 10; // set the base of the next digit
- Num2 = Num2 / 10; // cut the last digit of the num2
- Num1 = Num1 / 10; // cut the last digit of the num1
- }
- System.out.println("The number is : " +newNum);
- }
- }
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise3 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s = new Scanner(System.in);
- int maxDigit=0, Num, curDigit, temp;
- System.out.println("Please, Enter the first number ? ");
- Num = s.nextInt();
- temp = Num;
- while (temp > 0)
- {
- curDigit = temp % 10; // to get the right most digit of num
- if(curDigit > maxDigit) //Check which digit is bigger
- {
- maxDigit = curDigit ;
- }
- temp = temp /10; // Cut the last digit from the number
- }
- System.out.println("The number is : " +maxDigit);
- }
- }
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise4 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s = new Scanner(System.in);
- int temp, Numbase10=0, Num, power=0;
- System.out.println("Please, Enter A Bianary number - Example 1001 ? ");
- Num = s.nextInt();
- while (true)
- {
- if(Num == 0){ // If num of digits = 0 Exit while Else
- break;
- }else
- {
- temp = Num % 10; //get the last digit
- Numbase10 += temp*Math.pow(2,power); //use 2^ power = 0 Times the digit read
- Num = Num / 10; // remove digit
- power++; // add 1 to power next digit 2^1 time Digit
- }
- }
- System.out.println("The number is : " +Numbase10); // print the base 10 Number
- }
- }
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise5 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s = new Scanner(System.in);
- int temp=0, Num;
- String DecimalNum = "";
- System.out.println("Please, Enter A Decimal number - Example 0-9 allowed ? ");
- Num = s.nextInt();
- while (Num > 0) {
- temp = Num % 2;
- DecimalNum = temp + DecimalNum;
- Num = Num / 2;
- }
- System.out.println("The Decimal number is : " + (DecimalNum)); // print the base 10 number
- }
- }
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise6 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int base, i, j, k;
- Scanner s = new Scanner(System.in);
- System.out.println("Enter any number of stars for the base :");
- base = s.nextInt();
- for (i = 1; i <= base; i++) { //loop until base entered reached
- for (j = 1; j <= i; j++)//prints the space
- System.out.print(" ");
- for (j = 1; j <= base - i; j++)//prints the stars = base entered - 1 star
- System.out.print("*");
- System.out.println(); // new Line
- }
- }
- }
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise7 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int rows = 1, base, i, j, k;
- Scanner s = new Scanner(System.in);
- System.out.println("Enter any number of stars for the base :");
- base = s.nextInt();
- for (i = 1; i <= base ; i++) { // prints the first triangle of stars - left
- for (j = 1; j <= i; j++)
- System.out.print("*");
- for (k = 1; k <= (base * 2) - 2 * i; k++) // print the empty spaces
- System.out.print(" ");
- for (j = 1; j <= i; j++)// Prints the Right stars
- System.out.print("*");
- System.out.println();
- }
- }
- }
- package HWpresentation3;
- import java.util.Random;
- import java.util.Scanner;
- public class Exercise8 {
- // TODO Auto-generated method stub
- public static void main(String args[]) {
- Random random = new Random();
- Scanner input = new Scanner(System.in);
- int MIN = 1; //Initilize our input from 1 - 100
- int MAX = 100;
- int comp = random.nextInt(MAX - MIN + 1) + MIN; // Computer Randomly choose a number
- int user;
- int guesses = 0; // counter for how many time user gussed
- do {
- System.out.print("Guess a number between 1 and 100: ");// prompt user to try find number Computer selected
- user = input.nextInt();
- guesses++;
- if (user > comp) // check the gussed number
- System.out.println("My number is less than " + user + "."); //prompt user if number gussed smaller
- else if (user < comp)
- System.out.println("My number is greater than " + user + ".");
- else // user got a hit and find the Random number generated by computer
- System.out.println("Well done! " + comp + " was my number! You guessed it in " + guesses + " guesses.");
- } while (user != comp); // Condition found the number
- }
- }
- package HWpresentation3;
- import java.util.Scanner;
- public class Exercise9 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s = new Scanner(System.in);
- int col, frame, rows, subF;
- //System.out.println("Enter n the number of squares you wish?");
- // n = s.nextInt();
- int n = (int)(Math.random()*10);
- System.out.println("The number Randomly selected is d: "+n);
- for (frame = 1; frame <= n; frame++) {
- for (subF = 1; subF <= n; subF++) {
- for (rows = 1; rows <= n; rows++) {
- for (col = 1; col <= n; col++) {
- System.out.print("*");
- }
- System.out.print(" ");
- }
- System.out.println();
- }
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment