Week 2 assignment:
|
|
- Lucinda Cain
- 5 years ago
- Views:
Transcription
1 Week 2 assignment: Assignments: 1. Write a Java program to check whether a number is Buzz or not. 2. Write a Java program to calculate factorial of Write a Java program for Fibonacci series. 4. Write a Java program to reverse a number. 5. Admission to a professional course is subject to the following conditions: (a) marks in Mathematics >= 60 (b) marks in Physics >=50 (c) marks in Chemistry >=40 (d) Total in all 3 subjects >=200 (Or) Total in Maths & Physics>=150 Given the marks in the 3 subjects of n (user input) students, write a program to process the applications to list the eligible candidates. 6. Write a Java program to find all roots of a quadratic equation. 7. Write a Java program to calculate the sum of natural numbers up to a certain range. 8. Write a Java program to print all multiple of 10 between a given interval. 9. Write a Java program to generate multiplication table. 10. Write a Java program to find HCF of two Numbers. 11. Write a Java program to find LCM of two Numbers. 12. Write a Java program to count the number of digits of an integer. 13. Write a Java program to calculate the exponential of a number. 14. Write a Java program to check whether a number is palindrome or not. 15. Write a Java program to check whether a number is prime or not. 16. Write a Java program to convert a Binary Number to Decimal and Decimal to Binary. 17. Write a Java program to find median of a set of numbers. 18. Write a program to compute the value of Euler s number that is used as the base of natural logarithms. Use the following formula. e= 1+ 1/1! +1 /2! + 1/ /n! 19. Write a Java program to generate all combination of 1, 2, or 3 using loop. 20. Write a Java program to read two integer values m and n and to decide and print whether m is multiple of n. 21. Write a Java program to display prime numbers between a given interval. 22. Write a Java program to check whether a given number is Armstrong Number or not. Write Java programs for the patterns given bellow: (23-25)
2 1. import java.util.*; class Input int a; void method1() Scanner sc= new Scanner(System.in); System.out.print("Enter the number : "); a=sc.nextint(); void method2() if(a%7==0) System.out.println("It is a buzz number "); else if(a%10==7) System.out.println("It is a buzz number "); else System.out.println("It is not a buzz number "); class Buzz public static void main(string args[]) Input obj= new Input(); obj.method1(); obj.method2();
3 2. import java.util.*; class Fact void fac() System.out.println("Factorial of 12"); long sum=1; for(int i=2;i<=12;i++) sum=sum*i; System.out.println("The value is " +sum); class Factorial public static void main(string args[]) Fact ob=new Fact(); ob.fac();
4 3. import java.util.*; class Fibb void fi() System.out.println("Enter the length"); int s=sc.nextint(); int a=0,j=1; System.out.print("0 1 "); for(int i=0;i<s;i++) int sum=a+j; a=j; j=sum; System.out.print(sum+" "); class Fibonacci public static void main(string args[]) Fibb ob=new Fibb(); ob.fi();
5 4. import java.util.*; class Revno void rv() System.out.println("Enter the no"); int s=sc.nextint(); int rev=0; while(s>0) int rem=s%10; rev=rev*10+rem; s=s/10; System.out.println( THE REVERSE IS +rev); class Reverse public static void main(string args[]) Revno ob=new Revno(); ob.rv();
6 5. import java.util.*; class Addm void ad() System.out.println("Enter the marks of Maths, Physics, Chemistry"); int m=sc.nextint(); int p=sc.nextint(); int c=sc.nextint(); int tot2=m+p; int total=m+p+c; if((m>=60 && p>=50 && c>=40 && total>=200 ) tot2>=150) System.out.println("Admission Succeded"); else System.out.println("No Admission"); class Addmission public static void main(string args[]) Addm ob=new Addm(); ob.ad();
7 6. import java.util.*; class Quad double x,y; void ma() System.out.println("Enter the Quadratic Eq: (_x^2)+(_x)+ _"); int a=sc.nextint(); int b=sc.nextint(); int c=sc.nextint(); x=math.sqrt((math.pow(b,2)+(4*a*c))); y=(math.pow(b,2)); double root=(y+x/2*a); System.out.println("The root is :"+root); class Quadractic public static void main(string args[]) Quad ob=new Quad(); ob.ma();
8 7. import java.util.*; class Sum int n=0; void sm(int b) for(int i=0;i<b;i++) n=n+i; System.out.println("The sum is =" +n); class Sm public static void main(string args[]) System.out.println("Enter the input:"); int a=sc.nextint(); Sum obj=new Sum; obj.sm(a);
9 8. import java.util.*; class Range void ma() System.out.println("Enter the Range"); int ran=sc.nextint(); int m=10; for(int a=1;a<=ran;a++) int sum=a*m; System.out.println("10 * "+a+"="+sum); class Mult public static void main(string args[]) Range ob=new Range(); ob.ma();
10 9. import java.util.*; class Multab void ma() System.out.println("Enter the Multiplier No"); int m=sc.nextint(); System.out.println("Enter the Range"); int ran=sc.nextint(); for(int a=1;a<=ran;a++) int sum=a*m; System.out.println(m+" * "+a+"="+sum); class Multiplicationtable public static void main(string args[]) Multab ob=new Multab(); ob.ma();
11 10. import java.util.scanner; class Hcfs void fndhcf(int a,int b) int hcf=1; for(int i=1;i<=a;i++) if(a%i==0 && b%i==0) hcf=i; System.out.println("hcf is "+hcf); class Hcf public static void main(string args[]) System.out.println("Enter Number"); int x =sc.nextint(); System.out.println("Enter Number"); int y =sc.nextint(); Hcfs obj=new Hcfs(); obj.fndhcf(x,y);
12 11. import java.util.scanner; class A int n1,n2,gcd; void input() System.out.println("Enter the First no."); n1=sc.nextint(); System.out.println("Enter the Second no."); n2=sc.nextint(); void lcm() for(int i = 1; i <= n1 && i <= n2; ++i) if(n1 % i==0 && n2 % i==0) gcd = i; int lcm=(n1*n2)/gcd; System.out.printf("LCM of %d and %d is %d", n1, n2, lcm); class LCM public static void main(string ar[]) A a=new A(); a.input(); a.lcm();
13 12. import java.util.*; class Count void ma() System.out.println("Enter the No"); int m=sc.nextint(); int c=0; while(m>0) m=m/10; c++; System.out.println("The no of digits "+c); class Countint public static void main(string args[]) Count ob=new Count(); ob.ma();
14 13. import java.util.scanner; class A double y=0,x=0,n; void input() System.out.println("Enter the no."); n=sc.nextint(); System.out.println("Enter the power"); x=sc.nextint(); void calc() y=math.pow(n,x); System.out.println("THE NO. is:"+n+" Power is:"+x+" the total value is:"+y); class Power public static void main(string ar[]) A a=new A(); a.input(); a.calc();
15 14. import java.util.scanner; class A int r,x,sum=0,n; void input() System.out.println("Enter the no."); n=sc.nextint(); void calc() x=n; while(n!=0) r=n%10; sum=(sum*10)+r; n=n/10; if(n==x) System.out.println("PALINDROME NO"); else System.out.println("NOT PALINDROME NO"); class Palindrome public static void main(string ar[]) A a=new A(); a.input(); a.calc();
16 15. import java.util.scanner; class A int y=0,x=0,n; void input() System.out.println("Enter the no."); n=sc.nextint(); void pm() for(y=1;y<=n;y++) if(n%y==0) x++; if(x==2) System.out.println("PRIME NO."); else System.out.println("NOT PRIME NO."); class Prime public static void main(string [] args) A a=new A(); a.input(); a.pm();
17 16. import java.util.scanner; class A int p,decimal=0,n,r,n1,i,x,j; int []a=new int[100]; void input() System.out.println("Enter the Binary no."); n=sc.nextint(); System.out.println("Enter the Decimal no."); n1=sc.nextint(); void btod() x=n; while(n!=0) decimal+=((n%10)*math.pow(2,p)); n=n/10; p++; System.out.println("Binary is:"+x+"converted to decimal:"+decimal); void dtob() x=n1; while(n1!=0) r=n1%2; a[i]=r; n1=n1/2; i++; System.out.print("Decimal is:"+x+"converted to Binary:"); for(j=i-1;j>=0;j--) System.out.print(a[j]); class BinaryDecimal public static void main(string ar[]) A a=new A(); a.input(); a.btod(); a.dtob();
18 17. import java.util.scanner; class A int x,n,i; double z; int a[]=new int[50]; void input() System.out.println("Enter the no."); n=sc.nextint(); void calc() for(i=1;i<=n;i++) a[i]=sc.nextint(); x=n/2; if(n%2==0) z=(a[x]+a[x+1]); System.out.println("MEDIAN is:"+(z/2)); else System.out.println("MEDIAN is:"+a[x+1]); //end of class class Median public static void main(string ar[]) A a=new A(); a.input(); a.calc();
19 18. import java.util.scanner; class A double m,n=0,e=0,fact=1; void input() System.out.println("Enter the last no."); n=sc.nextdouble(); void pm() for(int i=1;i<(n);i++) fact=fact*i; m=(1/fact); System.out.println("Series:"+m); e=e+m; System.out.println("Sum is:"+(e+1)); class Euler public static void main(string ar[]) A a=new A(); a.input(); a.pm();
20 19. class A int i,j,k; void calc() for(i=1;i<=3;i++) for(j=1;j<=3;j++) for(k=1;k<=3;k++) System.out.println("ALL POSSIBLES Combination of no.s are:"+i+j+k); class Combinations public static void main(string ar[]) A a=new A(); a.calc();
21 20. import java.util.scanner; class A int m,n; void input() System.out.println("Enter the First no. SAY n"); n=sc.nextint(); System.out.println("Enter the Second no. SAY m"); m=sc.nextint(); void pm() if(n%m==0) System.out.println("THE NO."+n+"is multiple of"+m); else System.out.println("NOT MULTIPLE"); class MultipleofNo public static void main(string ar[]) A a=new A(); a.input(); a.pm();
22 21. import java.util.scanner; class A int low,high,i,j,x; void input() System.out.println("Enter the lower limit"); low=sc.nextint(); System.out.println("Enter the upper limit"); high=sc.nextint(); void pm() while (low < high) boolean flag = false; for(int i = 2; i <= low/2; ++i) // condition for nonprime number if(low % i == 0) flag = true; break; //end of if //end of for if (!flag) System.out.print(low + " "); ++low; //end of while //end of function pmm //end of class class LimitPrime public static void main(string a[]) A obj=new A(); obj.input(); obj.pm();
23 22. import java.util.scanner; class Am int y=0,m,x=0,n; void input() System.out.println("Enter the no."); n=sc.nextint(); void amg() m=n; while(n!=0) x=n%10; y=y+x*x*x; n=n/10; if(m==y) System.out.println("AMSTRONG NO."); else System.out.println("NOT AMSTRONG NO."); class Amstrong public static void main(string [] args) Am a=new Am(); a.input(); a.amg();
24 23. import java.util.*; class Patm void makingofpattern(int a) int k=1; for (int i = 1; i <= a/3; i++) for (int j = 1; j <= i+1; j++) System.out.print(k+" "); k++; System.out.println(); class Pattern1 public static void main(string ar[]) System.out.println("Enter your limit for pattern "); int p=sc.nextint(); Patm obj=new Patm(); obj.makingofpattern(p); //end of main //end of class
25 24. import java.util.*; class Patm void makingofpattern(int a) for (int i = 1; i <= a; i++) for (int j = 1; j <= a - i; j++) System.out.print(" "); for (int k = i; k >= 1; k--) System.out.print(k); for (int l = 2; l <= i; l++) System.out.print(l); System.out.println(); class Pattern1 public static void main(string ar[]) System.out.println("Enter your limit for pattern "); int p=sc.nextint(); Patm obj=new Patm(); obj.makingofpattern(p); //end of main //end of class
26 25. import java.util.*; class Patm void makingofpattern(int a) int k=1; for (int i = 1; i <= a; i++) //Printing i spaces at the beginning of each row for (int j = 1; j < i; j++) System.out.print(" "); //Printing i to rows value at the end of each row for (int j = i; j <= a-1; j++) if(j==i j==a-1) System.out.print(k+" "); else System.out.print(" "); k++; System.out.println(); class Pattern1 public static void main(string ar[]) System.out.println("Enter your limit for pattern "); int p=sc.nextint(); Patm obj=new Patm(); obj.makingofpattern(p+1); //end of main //end of class
PROGRAM 1: Acme Academy Mobile No Page 1
PROGRAM 1: Write a program using switch case to input a number and check whether the number is prime or composite. Input case 1 for prime number and case 2 for composite number. import java.util.*; class
More informationChapter 18: Repetitive Structures
Chapter 18: Repetitive Structures Practice Questions A. Answer the following questions: 1. What is a loop? Discuss Elements that Control a Loop. Ans. Loop is a repetitive structure that allows a group
More informationWrite a program which converts all lowercase letter in a sentence to uppercase.
Write a program which converts all lowercase letter in a sentence to uppercase. For Example: 1) Consider a sentence "welcome to Java Programming!" its uppercase conversion is " WELCOME TO JAVA PROGRAMMING!"
More informationPROGRAM: import java.util.scanner;
1. import java.util.scanner; public class printname public static void main(string[] args) System.out.println("Input Your Name:"); String name = new Scanner(System.in).nextLine(); System.out.println("My
More informationMidterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationLoops. CSE 114, Computer Science 1 Stony Brook University
Loops CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation Suppose that you need to print a string (e.g., "Welcome to Java!") a user-defined times N: N?
More informationAP COMPUTER SCIENCE A
AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks
More informationIntroduction to Computer Science Unit 2. Notes
Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and
More informationIntroduction to Computer Science Unit 2. Notes
Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and
More informationM105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014
M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case
More informationpackage import public class public static void int out new for break else out else out
//1) WAP in JAVA to check whether no is prime or not. package finalpracs; import java.util.scanner; public class Prime public static void main(string args[]) int a, i, flag=0; System.out.println("Enter
More informationAP CS Unit 3: Control Structures Notes
AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts
More informationCOMP-202 Unit 4: Programming With Iterations. CONTENTS: The while and for statements
COMP-202 Unit 4: Programming With Iterations CONTENTS: The while and for statements Introduction (1) Suppose we want to write a program to be used in cash registers in stores to compute the amount of money
More informationExample: Monte Carlo Simulation 1
Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149
More informationLoops. GEEN163 Introduction to Computer Programming
Loops GEEN163 Introduction to Computer Programming Simplicity is prerequisite for reliability. Edsger W. Dijkstra Programming Assignment A new programming assignment has been posted on Blackboard for this
More informationB.Sc (Computer Science) Programming in Java Lab Programs
B.Sc (Computer Science) Programming in Java Lab Programs 1 1. Write java programs to find the following. a) Largest of given Three Numbers b) Reverses the digits of a number c) Given number is prime or
More informationProgramming Questions and Solutions in Java (15CS561)
This document can be downloaded from www.chetanahegde.in with most recent updates. 1 Programming Questions and Solutions in Java (15CS561) 1. Write a program to find area of circle. class Circle int r=3;
More informationOct Decision Structures cont d
Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements
More information1. Basics 1. Write a program to add any two-given integer. Algorithm Code 2. Write a program to calculate the volume of a given sphere Formula Code
1. Basics 1. Write a program to add any two-given integer. Algorithm - 1. Start 2. Prompt user for two integer values 3. Accept the two values a & b 4. Calculate c = a + b 5. Display c 6. Stop int a, b,
More informationTop-Down Program Development
Top-Down Program Development Top-down development is a way of thinking when you try to solve a programming problem It involves starting with the entire problem, and breaking it down into more manageable
More informationUNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA C ASSIGNMENTS
UNIVERSITY OF ENGINEERING & MANAGEMENT, KOLKATA C ASSIGNMENTS All programs need to be submitted on 7th Oct 206 by writing in hand written format in A4 sheet. Flowcharts, algorithms, source codes and outputs
More informationExam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:
كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this
More informationWeb-CAT submission URL: CAT.woa/wa/assignments/eclipse
King Saud University College of Computer & Information Science CSC111 Lab04 Conditional Statements All Sections ------------------------------------------------------------------- Instructions Web-CAT
More informationChapter 4: Control Structures I
Chapter 4: Control Structures I Java Programming: From Problem Analysis to Program Design, Second Edition Chapter Objectives Learn about control structures. Examine relational and logical operators. Explore
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max
More informationCh. 6. User-Defined Methods
Ch. 6 User-Defined Methods Func5onal Abstrac5on Func5onal regarding func5ons/methods Abstrac5on solving a problem in a crea5ve way Stepwise refinement breaking down large problems into small problems The
More informationITERATION WEEK 4: EXMAPLES IN CLASS
Monday Section 2 import java.util.scanner; public class W4MSection2 { ITERATION WEEK 4: EXMAPLES IN CLASS public static void main(string[] args) { Scanner input1 = new Scanner (System.in); int CircleCenterX
More informationIntroduction to Computer Science, Shimon Schocken, IDC Herzliya. Lectures Control Structures
Introduction to Computer Science, Shimon Schocken, IDC Herzliya Lectures 3.1 3.2 Control Structures Control Structures, Shimon Schocken IDC Herzliya, www.intro2cs.com slide 1 Control structures A program
More informationCOMPUTER APPLICATIONS
Percentage of Candidates COMPUTER APPLICATIONS STATISTICS AT A GLANCE Total Number of students who took the examination 99,856 Highest Marks Obtained 100 Lowest Marks Obtained 27 Mean Marks Obtained 83.28
More informationProgramming Constructs Overview. Method Call System.out.print( hello ); Method Parameters
Programming Constructs Overview Method calls More selection statements More assignment operators Conditional operator Unary increment and decrement operators Iteration statements Defining methods 27 October
More informationComputer Applications Answer Key Class IX December 2017
Computer Applications Answer Key Class IX December 2017 Question 1. a) What are the default values of the primitive data type int and float? Ans : int = 0 and float 0.0f; b) Name any two OOP s principle.
More informationCORE JAVA BASIC PROGRAMMING PROBLEMS FOR BEGINNERS PDF1. Learn all java programming concepts to crack java interviews and tests
CORE JAVA BASIC PROGRAMMING PROBLEMS FOR BEGINNERS PDF1 www.javalearnings.com Learn all java programming concepts to crack java interviews and tests //Java Program to Print Multiplication Table of a Given
More informationCS212 Midterm. 1. Read the following code fragments and answer the questions.
CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");
More informationJava Programs. System.out.println("Dollar to rupee converion,enter dollar:");
Java Programs 1.)Write a program to convert rupees to dollar. 60 rupees=1 dollar. class Demo public static void main(string[] args) System.out.println("Dollar to rupee converion,enter dollar:"); int rs
More informationCSC141, Computer Science I, Instructor: Dr. Zhen Jiang, Test 2
CSC141, Computer Science I, Instructor: Dr. Zhen Jiang, Test 2 Name(print) Student Number Page Points Score 2 8 3 8 4 8 5 6 6 8 7 8 8 10 9 6 10 6 11 11 12 21 Total 100 1 Part 1 (56 pts): Select the correct
More informationCS141 Programming Assignment #6
CS141 Programming Assignment #6 Due Sunday, Nov 18th. 1) Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2 1
More informationFaculty of Science Midterm. COMP-202B - Introduction to Computing I (Winter 2008)
Student Name: Student Number: Section: Faculty of Science Midterm COMP-202B - Introduction to Computing I (Winter 2008) Friday, March 7, 2008 Examiners: Prof. Jörg Kienzle 18:15 20:15 Mathieu Petitpas
More informationCSC 231 DYNAMIC PROGRAMMING HOMEWORK Find the optimal order, and its optimal cost, for evaluating the products A 1 A 2 A 3 A 4
CSC 231 DYNAMIC PROGRAMMING HOMEWORK 10-1 PROFESSOR GODFREY MUGANDA 1. Find the optimal order, and its optimal cost, for evaluating the products where A 1 A 2 A 3 A 4 A 1 is 10 4 A 2 is 4 5 A 3 is 5 20
More informationFinal Examination Semester 2 / Year 2011
Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2011 COURSE : FUNDAMENTALS OF SOFTWARE DESIGEN AND DEVELOPMENT COURSE CODE : PROG1003 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE
More informationChapter 10: Recursive Problem Solving
2400 COMPUTER PROGRAMMING FOR INTERNATIONAL ENGINEERS Chapter 0: Recursive Problem Solving Objectives Students should Be able to explain the concept of recursive definition Be able to use recursion in
More informationArrays. Eng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays
More informationOver and Over Again GEEN163
Over and Over Again GEEN163 There is no harm in repeating a good thing. Plato Homework A programming assignment has been posted on Blackboard You have to convert three flowcharts into programs Upload the
More informationCOE 212 Engineering Programming. Welcome to the Final Exam Tuesday December 15, 2015
1 COE 212 Engineering Programming Welcome to the Final Exam Tuesday December 15, 2015 Instructors: Dr. Salim Haddad Dr. Bachir Habib Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1.
More informationRecursive Problem Solving
Recursive Problem Solving Objectives Students should: Be able to explain the concept of recursive definition. Be able to use recursion in Java to solve problems. 2 Recursive Problem Solving How to solve
More informationSome Sample AP Computer Science A Questions - Solutions
Some Sample AP Computer Science A Questions - s Note: These aren't from actual AP tests. I've created these questions based on looking at actual AP tests. Also, in cases where it's not necessary to have
More informationExample. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct.
Example Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct. 1... 2 Scanner input = new Scanner(System.in); 3 int x = (int) (Math.random()
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 000 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationimport java.util.scanner; public class Assigment12 { int decnumber; public Assigment12(int number,int base){ if (base == 10) this.decnumber = number;
import java.util.scanner; public class Assigment12 { int decnumber; public Assigment12(int number,int base){ if (base == 10) this.decnumber = number; if (base == 2) this.decnumber = bin2dec(number); if
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 000 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationCombined Assignment Operators. Flow of Control. Increment Decrement Operators. Operators Precedence (Highest to Lowest) Slide Set 05: Java Loops
Flow of control Flow of Control Program instruction execution sequence Sequential Control Structure Selection (Branching) Control Structure Repetition (Loop) Control Structure Operator Usage Relational
More informationCOE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.
1 COE 212 Engineering Programming Welcome to Exam II Thursday April 21, 2016 Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book.
More informationRepetition, Looping. While Loop
Repetition, Looping Last time we looked at how to use if-then statements to control the flow of a program. In this section we will look at different ways to repeat blocks of statements. Such repetitions
More informationQuestion 1 [20 points]
Question 1 [20 points] a) Write the following mathematical expression in Java. c=math.sqrt(math.pow(a,2)+math.pow(b,2)- 2*a*b*Math.cos(gamma)); b) Write the following Java expression in mathematical notation.
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationIntroduction to Computer Science, Winter Term Lab Exercise 6 Discussion:
German University in Cairo Faculty of Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Rimon Elias Introduction to Computer Science, Winter Term 2013-2014 Lab Exercise 6 Discussion: 21.12.2013-26.12.2013
More informationWhat two elements are usually present for calculating a total of a series of numbers?
Dec. 12 Running Totals and Sentinel Values What is a running total? What is an accumulator? What is a sentinel? What two elements are usually present for calculating a total of a series of numbers? Running
More informationCS141 Programming Assignment #5
CS141 Programming Assignment #5 Due Wednesday, Nov 16th. 1) Write a class that asks the user for the day number (0 to 6) and prints the day name (Saturday to Friday) using switch statement. Solution 1:
More informationGuru Gobind Singh Public School Sector V,B Bokaro Steel City Annual IP Assignment Class 11
Guru Gobind Singh Public School Sector V,B Bokaro Steel City Annual IP Assignment Class 11 1. What will be the output of given expression : int a=7; System.out.println(++a + + a-- + + a+1 + +a++); System.out.println(a);
More informationExpression statements are formed by adding a semicolon to the end of certain types of expressions.
Expression statements are formed by adding a semicolon to the end of certain types of expressions. Variable declaration statements declare variables. int width, height, area; String hello = "Hello, world!";
More informationTop-down programming design
1 Top-down programming design Top-down design is a programming style, the mainstay of traditional procedural languages, in which design begins by specifying complex pieces and then dividing them into successively
More informationJava Classes: Random, Character A C S L E C T U R E 6
Java Classes: Random, Character A C S - 1903 L E C T U R E 6 Random An instance of the Random can be used to generate a stream of random values Typical process: 1. Create a Random object 2. Use the object
More informationCIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION
CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)
More informationCSE 114 Computer Science I
CSE 114 Computer Science I Iteration Cape Breton, Nova Scotia What is Iteration? Repeating a set of instructions a specified number of times or until a specific result is achieved How do we repeat steps?
More informationJump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.
Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:
More informationCS Computers & Programming I Review_01 Dr. H. Assadipour
CS 101 - Computers & Programming I Review_01 Dr. H. Assadipour 1. What is the output of this program? public class Q_01 public static void main(string [] args) int x=8; int y=5; double z=12; System.out.println(y/x);
More informationJump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.
Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:
More informationPLACEMENT PREPRATION TEST ANS
1) CTE(Compile Time Error) 2) 2 1 www.javapadho.com 3) 1 2 4) 46 36 5) true false false false true true 6) False 7) 19 8) CTE (Unreachable code ) 9) Abcxyzhellotest 10) Error occurred RTE 11) From test
More informationAssignment2013 Please use this document only for verifying if your programs are right. Do not blindly copy paste and waste your time.
Please use this document only for verifying if your programs are right. Do not blindly copy paste and waste your time. 11/3/2013 TechSparx Computer Training Center Saravanan.G Please use this document
More informationTasks for fmri-setting (Tasks of first and second pilot study at the end)
Tasks for fmri-setting (Tasks of first and second pilot study at the end) 1. Faculty int result = 1; int x = 4; while (x > 1) { result = result * x; x--; 7. Find max in list of numbers public static void
More informationVOLUME II CHAPTER 9 INTRODUCTION TO C++ HANDS ON PRACTICE PROGRAMS
VOLUME II CHAPTER 9 INTRODUCTION TO C++ HANDS ON PRACTICE PROGRAMS 1. Write C++ programs to interchange the values of two variables. a. Using with third variable int n1, n2, temp; cout
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationCOMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz
COMP-202B - Introduction to Computing I (Winter 2011) - All Sections Example Questions for In-Class Quiz The in-class quiz is intended to give you a taste of the midterm, give you some early feedback about
More informationComputação I. Exercises. Leonardo Vanneschi NOVA IMS, Universidade Nova de Lisboa. Leonardo Vanneschi Computação I NOVA IMS
Computação I Exercises Leonardo Vanneschi NOVA IMS, Universidade Nova de Lisboa 1 Exercise 1 Write a Java program composed by: a. A method called myaverage that has the following parameters: an array A
More informationMenu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:
Menu Driven Systems While loops, menus and the switch statement Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list while loops recap
More informationC212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.
C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What
More informationCS 101 Spring 2007 Midterm 2 Name: ID:
You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure
More informationCS171:Introduction to Computer Science II
CS171:Introduction to Computer Science II Department of Mathematics and Computer Science Li Xiong 9/7/2012 1 Announcement Introductory/Eclipse Lab, Friday, Sep 7, 2-3pm (today) Hw1 to be assigned Monday,
More informationCOE 212 Engineering Programming. Welcome to Exam II Monday May 13, 2013
1 COE 212 Engineering Programming Welcome to Exam II Monday May 13, 2013 Instructors: Dr. Randa Zakhour Dr. Maurice Khabbaz Dr. George Sakr Dr. Wissam F. Fawaz Name: Solution Key Student ID: Instructions:
More informationPrasanth Kumar K(Head-Dept of Computers)
B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Unit-II 1 1. Define operator. Explain the various operators in Java. (Mar 2010) (Oct 2011) Java supports a rich set of
More informationAlgorithms 4. Odd or even Algorithm 5. Greatest among three numbers Algorithm 6. Simple Calculator Algorithm
s 4. Odd or even Step 3 : If number divisible by 2 then Print "Number is Even" Step 3.1 : else Print "Number is Odd" Step 4 : Stop 5. Greatest among three numbers Step 2 : Read values of a, b and c Step
More informationJava Coding 3. Over & over again!
Java Coding 3 Over & over again! Repetition Java repetition statements while (condition) statement; do statement; while (condition); where for ( init; condition; update) statement; statement is any Java
More informationCEN 414 Java Programming
CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea
More informationBuilding Java Programs
Building Java Programs Chapter 5 Lecture 5-4: do/while loops, assertions reading: 5.1, 5.5 1 The do/while loop do/while loop: Performs its test at the end of each repetition. Guarantees that the loop's
More informationIn this chapter, you will:
Java Programming: Guided Learning with Early Objects Chapter 4 Control Structures I: Selection In this chapter, you will: Make decisions with the if and if else structures Use compound statements in an
More informationLesson 7 Part 2 Flags
Lesson 7 Part 2 Flags A Flag is a boolean variable that signals when some condition exists in a program. When a flag is set to true, it means some condition exists When a flag is set to false, it means
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements
WIT COMP1000 Simple Control Flow: if-else statements Control Flow Control flow is the order in which program statements are executed So far, all of our programs have been executed straight-through from
More informationRecitation: Loop Jul 7, 2008
Nested Loop Recitation: Loop Jul 7, 2008 1. What is the output of the following program? Use pen and paper only. The output is: ****** ***** **** *** ** * 2. Test this program in your computer 3. Use "for
More informationChapter 5: Programming in Java
Chapter 5: Programming in Java Practice Questions ----------------------------->Objective-Type Questions
More informationMore Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements
More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input
More informationAssignment-1 Final Code. Student.java
package com.ds.assgn1a; public class Student { public int rollno; public String name; public double marks; Assignment-1 Final Code Student.java public Student(int rollno, String name, double marks){ this.rollno
More informationRecursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples
Recursion General Algorithm for Recursion When to use and not use Recursion Recursion Removal Examples Comparison of the Iterative and Recursive Solutions Exercises Unit 19 1 General Algorithm for Recursion
More informationBuilding Java Programs
Building Java Programs Chapter 5 Random Numbers reading: 5.1, 5.6 1 http://xkcd.com/221/ 2 The while loop while loop: Repeatedly executes its body as long as a logical test is true. while (test) { statement(s);
More informationFor that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.
Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, java provides control structures
More informationINFO Object-Oriented Programming
INFO0062 - Object-Oriented Programming Exercise session #1 - Basic Java programs Jean-François Grailet University of Liège Faculty of Applied Sciences Academic Year 2017-2018 Creating a simple Java program
More informationFor that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.
Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may bifurcate, repeat code or take decisions. For that purpose, java provides control structures
More informationIteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times
Iteration: Intro Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times 2. Posttest Condition follows body Iterates 1+ times 1 Iteration: While Loops Pretest loop Most general loop construct
More informationCMPS 11 Introduction to Programming Midterm 1 Review Problems
CMPS 11 Introduction to Programming Midterm 1 Review Problems Note: The necessary material for some of these problems may not have been covered by end of class on Monday, the lecture before the exam. If
More information1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005
1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005 Name: E-mail Address: TA: Section: You have 80 minutes to complete this exam. For coding questions, you do not need to
More informationCS111: PROGRAMMING LANGUAGE II
1 CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1: Introduction Lecture Contents 2 Course info Why programming?? Why Java?? Write once, run anywhere!! Java basics Input/output Variables
More informationESc101 : Fundamental of Computing
ESc101 : Fundamental of Computing I Semester 2008-09 Lecture 37 Analyzing the efficiency of algorithms. Algorithms compared Sequential Search and Binary search GCD fast and GCD slow Merge Sort and Selection
More information