4) Write a java program where you will use while loop, where if condition is equal to 2 (or any other choice of your number) then it will break the while condition.
Steps:
1) Declare variable int (any name) which is equal to zero
2) Declare while condition which variable int is less then equal to 10
3) Declare print out where the value of variable is the same name that you declared in step 1
4) Declare condition if where variable of step 1 is == to two then break
5) Declare increment of variable that you declared in step 1 by one
6) Show system print
5) Write a java program with scanner object to input first number and second number as variable with input statement and system out print statement.
Steps:
1) Declare scanner object
2) Ask system out print for first number and declare variable first number
3) Ask system out print for second number and declare variable second number
4) Declare first for loop where variable int i has already a value (your choice), that i is less then equal to ? and i?
5) Declare the inner for loop where variable int j has already a value (your choice), that j is less then equal to ? and j?
6) Declare the variable sum where i and j use addition (or multiplication or subtraction/ your choice)
7) Declare the if condition where sum is greater then 8 (or your choice) then break statement
8) In the end print statement where i and j are using your computation of choice and displaying the sum. Note: be careful with bracket.
6) Write a program that lets the user enter the loan amount, number of years, and interest rate and displays the amortization schedule for the loan.
Steps: 1) Create scanner
2) Prompt the user to enter loan amount and declare double variable and relate to scanner input
3) Prompt the user to enter number of years and declare integer years and relate to scanner input
4) Prompt the user to enter annual interest rate and declare double variable and relate to scanner input
5) Calculate monthly interest rate: first create a double variable called monthlyRate which is equal to annualRate divided by 1200
6) Calculate monthly payement: first create double variable called monthlyPayement which is equal to loanAmount times monthlyRate divied by (1 - 1 / Math.pow(1 + monthlyRate, years * 12));
7) Display in console monthlyPayement
8) Display in console total amount with formula inside of prompt (monthlyPayement*12) * years);
9) Create so called amortization schedule: first create double variable called balance which is equal to loanAmount, principal, interest;
10) System.out.println ("Payment# Interest Principal Balance"); for (int i = 1; i <= years * 12; i++) { interest = monthlyRate * balance; principal = monthlyPayment - interest; balance = balance - principal; System.out.printf("%-13d%-13.2f%-13.2f%.2f\n", i, interest, principal, balance); }
Answer for Question 4:
import java.util.*;
public class Main
{
public static void main(String[] args) {
// declaring variable
int var=0;
// while condition
while (var<=10){
// printing variable
System.out.println(var);
// condition checks is var ==2
if (var==2){
// it breaks loop if it satisfied
break;
}
// incrementing variable
var++;
}
}
}
Answer for question number 5
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
int sum=0;
// promting user
System.out.println("Enter first number:");
// taking input from the user
int first_number=obj.nextInt();
System.out.println("Enter second number:");
// taking input from the user
int second_number=obj.nextInt();
for( int i=0; i <= first_number;i++){
for(int j=0;j<=second_number;j++){
sum=i+j;
if (sum>=8){
break;
}
}
}
System.out.println("sum:"+sum);
}
}
Get Answers For Free
Most questions answered within 1 hours.