Question

In: Computer Science

Question 1: Write a program to receive two integers as user input and then print: Sum...

Question 1:

Write a program to receive two integers as user input and then print:

  1. Sum
  2. Difference
  3. Product
  4. Average
  5. Maximum of the two
  6. Minimum of the two

You may use the min and max functions declared in the math class.

**********************************************************************************

Question 2:

An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly. Print out the balance for first three months.

For example:

Initial balance: 1000

Annual interest rate: 6.0

Balance after first month: 1005.00

Balance after second month: 1010.03

Balance after third month: 1015.08

**********************************************************************************

Question 3:

Scan a string as user input and print the following: (i) the first character, (ii) The last character.

For example:

String: Java

First letter: J

Last letter: a

Hint: use the length() and charAt() functions from String class.

Solutions

Expert Solution

Program1:

import java.util.*;

class Question1
{
public static void main(String args[])
{
int no1,no2;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the first number: ");
no1=sc.nextInt();
System.out.print("Enter the second number: ");
no2=sc.nextInt();
System.out.println("Sum: "+(no1+no2));
System.out.println("Difference: "+(no1-no2));
System.out.println("Product: "+(no1*no2));
double avg=(double)(no1+no2)/2;
System.out.println("Average: "+avg);
System.out.println("Maximum of the two: "+Math.max(no1,no2));
System.out.println("Miniimum of the two: "+Math.min(no1,no2));
}
}

Program2:

import java.util.*;

class Question2
{
public static void main(String args[])
{
double initialBal,annualInterestRate;
Scanner sc=new Scanner(System.in);
System.out.print("Enter the initial balance: ");
initialBal=sc.nextDouble();
System.out.print("Enter the annual Interest Rate: ");
annualInterestRate=sc.nextDouble();
double drate=annualInterestRate/100;
double balance1=initialBal * (Math.pow((1+drate/12),1));
System.out.printf("Balance after first month: %.2f\n",balance1);
double balance2=initialBal * (Math.pow((1+drate/12),2));
System.out.printf("Balance after second month: %.2f\n",balance2);
double balance3=initialBal * (Math.pow((1+drate/12),3));
System.out.printf("Balance after third month: %.2f\n",balance3);
}
}

Program3:

import java.util.*;

class Question3
{
public static void main(String args[])
{
String str;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a string: ");
str=sc.next();
//to get first and last character, using charAt() and length() functions.
System.out.println("First letter: "+str.charAt(0));
System.out.println("Last letter: "+str.charAt(str.length()-1));
}
}


Related Solutions

Question 1: 5pts Write a program to receive two integers as user input and then print:...
Question 1: 5pts Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: 10pts An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is...
Write MIPs program that will read two integers from the user and compute for the sum...
Write MIPs program that will read two integers from the user and compute for the sum and difference of the two integers. Ask the user whether he wants to repeat the program : "[Y/y] / [N/n] ?".
Martin wants to create a program that requires the user to input 10 integers then print...
Martin wants to create a program that requires the user to input 10 integers then print the total number of even integers, highest even integer, lowest even integer, total number of odd integers, highest odd integer, and lowest odd integer. If, however, the user inputs zero (0), the program will display “You have not yet entered 10 integers.” Below is the sample output of the program Martin created. Enter the integers: Integer 1: 15 Integer 2: 9 Integer 3: 71...
PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT)...
PART 1: WRITE A PROGRAM THAT TAKES IN TWO INTEGERS VALUE N AND M (USER INPUT) AND CALCULATES THE NTH FIBONACCI SUM USING RECURSION. EXAMPLE: OLD VERSION 0,1,1,2,3.. USING USER INPUT: 0, N, M ,N+M, (N+M)+M PART 2: WRITE THE SAME PROGRAM USING USER INPUT BUT USING A LOOP IN STEAD OF RECURSION. PYTHON
Write a program, ArrayRange, that asks the user to input integers and that displays the difference...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference between the largest and the smallest. You should ask the user the number of integers s/he would like to enter (this will allow you to set the length of the array). Allow the user to input all the numbers and then store them in the array. Search the array for the largest number, then search for the smallest, and finally compute the calculation. Display...
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers...
Program – version 1: Sum of Range Algorithm Write a program that will sum the integers between a given range (limit your range from 0 to 50). For example, if the user want to add the integers between (and including) 1 and 10, then the program should add: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 Algorithm: Program title/description Ask the user to input a start value in the...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Question Write a C program that asks the user to enter two integers x and n....
Question Write a C program that asks the user to enter two integers x and n. Then the program computes xn (=x * x * x …… (n times)) using for loop. and give me an output please use printf and scanf #include int main(void) {     //Declare required variables             //read two integers x , n from the keyboard                 //compute xn using for loop                     printf("< Your name >\n");...
Question 1: Write a program to receive a string from the user and compares the first...
Question 1: Write a program to receive a string from the user and compares the first and second half of the word and prints “First and Second Half Same” or “First and Second Half Different”. If the length of the word is odd, ignore the middle letter. For example: Run 1: Enter a word: abcdabc First and Second Half Same Run 2: Enter a word: abcde First and Second Half Different Hint: use the Math.floor() and length() to get the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT