




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





public class Gcd_Series_Fib { public static int Gcd(int a, int b){ int gcd = 1 ; for(int i = 1 ; i <= a && i <= b;i++) { if(a%i== 0 &&b%i== 0 ) gcd = i; } return gcd; } public static double Series(double start, double end, double inc) { double sum = 0 ; for(double i = start; i <= end; i += inc){ sum+= i; } return sum; } public static int Fib(int n) { if(n == 0 || n == 1 ) return n; else return (Fib(n- 2 )+ Fib(n- 1 )); } public static void main(String[] args) { System.out.println("GCD(8,4): " + Gcd( 8 , 4 )); System.out.println("Sum of [0.11 + 0.22 + 0.33 +...+ 2.2]= " + Series(0.11, 2.2, 0.11)); System.out.println("Fib(0): " + Fib( 0 )); System.out.println("Fib(3): " + Fib( 3 )); } }
public class grades { public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.print("Enter number of answers: "); int k = input.nextInt(); char [] answers = new char[k]; for(int i = 0 ; i < k; i++) { answers[i] = input.next().charAt( 0 ); } System.out.print("Enter number of students: "); int n = input.nextInt(); int m = k; char [][] list = new char[n][m]; System.out.println("Fill in the "+ n +" student's answers to "+ m + " questions") ; for (int i = 0 ;i<list.length;i++) { int count = 0 ; for (int j= 0 ;j<list[i].length;j++) { list[i][j] = input.next().charAt( 0 ); if(list[i][j]==(answers[j])) count++; } System.out.println("Student's " + (i+ 1 ) + " correct answers are " + count); } } }
public class Account { private int id; private double balance; private double annualInterestRate; private java.util.Date dateCreated; public Account() { dateCreated = new java.util.Date(); } public Account(int id, double balance) { this(); this.id = id; this.balance = balance; } public void setId(int id) { this.id = id; } public int getId() { return id; } public void setBalance(double balance) { this.balance = balance; } public double getBalance() { return balance; } public String getDateCreated() { return this.dateCreated.toString(); } public void setAnnualInterestRate(double annualInterestRate) { this.annualInterestRate = annualInterestRate; } public double getAnnualInterestRate() { return annualInterestRate; } public double getMonthlyInterestRate() { return (annualInterestRate / 1200 ); } public void withdraw(double amount) { this.balance - = amount; } public void deposit(double amount) { this.balance += amount; } }
public class TestAccount { public static void main(String[] args) { Account account = new Account( 2233 , 40000 ); account.setAnnualInterestRate(11.5); account.withdraw( 8500 ); account.deposit( 12500 ); System.out.println("Balance: $"+ account.getBalance()); System.out.println("Monthly Interest: "+ account.getMonthlyInterestRate()); System.out.println("Date Created: "+ account.getDateCreated()); } }