WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;

Slides:



Advertisements
Similar presentations
More Java Syntax. Scanner class Revisited The Scanner class is a class in java.util, which allows the user to read values of various types. There are.
Advertisements

CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 5: Program Logic and Indefinite Loops.
Loops –For For Reading for this Lecture, L&L, Part of 5.8.
Loops ISYS 350. Three Types of Loops while loop do while loop for loop.
TA: Nouf Al-Harbi NoufNaief.net :::
LAB 10.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Computer Programming Lab(4).
JAVA Control Structures: Repetition. Objectives Be able to use a loop to implement a repetitive algorithm Practice, Practice, Practice... Reinforce the.
Programming Methodology (1). import java.util.*; public class FindCost3 { public static void main(String[] args ) { Scanner sc = new Scanner(System.in);
Byung-Hyun Ha 프로그래밍 실습 #1 Byung-Hyun Ha
Chapter 5 Case Study. Chapter 5 The RPS Flowchart.
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
October 28, 2015ICS102: For Loop1 The for-loop and Nested loops.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
1 StringTokenization Overview l StringTokenizer class l Some StringTokenizer methods l StringTokenizer examples.
The if-else statement. The if-else statement in Java The if-else statement is the second conditional statement in Java The if-else statement selects one.
Chapter 4: Control Structures II
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
1 CSC 201: Computer Programming I Lecture 2 B. S. Afolabi.
Midterm 2 Review 1. 2 Object Oriented Programming Write a Date class. It should contain fields for day, month, year, number of months per year, and number.
1 Reasoning about assertions Readings: Assertions assertion: A statement that is either true or false. Examples:  Java was created in (true)
Java iteration statements ● Iteration statements are statements which appear in the source code only once, but it execute many times. ● Such kind of statements.
Review TEST 2 Chapters 4,5,7. QUESTION For which type of operands does the == operator always work correctly: (a) int, (b) double, or (c) String?
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Cumulative algorithms. 2 Adding many numbers How would you find the sum of all integers from ? // This may require a lot of typing int sum = 1 +
SELF STUDY. IF STATEMENTS SELECTION STRUCTURE if selection statement if … else selection statement switch selection statement.
Method overloading contd class OverloadDemo { public static void main(String args[]) { Overload ob = new Overload(); int resI; double resD; // call all.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
CS001 Introduction to Programming Day 6 Sujana Jyothi
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
CS1101X: Programming Methodology Recitation 10 Inheritance and Polymorphism.
Loops and Logic. Making Decisions Conditional operator Switch Statement Variable scope Loops Assertions.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING For Loop.
Chapter 2 Clarifications
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Arrays in Classes and Methods
using System; namespace Demo01 { class Program
Sum of natural numbers class SumOfNaturalNumbers {
Multiple if-else boolean Data
Computer Programming Methodology Input and While Loop
Repetition-Counter control Loop
Chapter 5: Control Structures II
TK1114 Computer Programming
Something about Java Introduction to Problem Solving and Programming 1.
הרצאה 3 אלמנטים בסיסיים בשפה
Building Java Programs
Building Java Programs
Chapter 4 Unordered List.
Building Java Programs
Decision statements. - They can use logic to arrive at desired results
The for-loop and Nested loops
חלק ה שימוש במציין שלם לערך תווי
Propositional Equivalences Rosen 5th and 6th Editions section 1.2
Recursive GCD Demo public class Euclid {
Self study.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Factoring if/else code
Classification of numbers
CSC1401 Input and Output (with Files)
Building Java Programs
Consider the following code:
More on iterations using
Presentation transcript:

WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true; Scanner sc=new Scanner(System.in); n= sc.nextInt();

for(int i=2 ; i< n/2 ; i++) { res=n%i; if( res== 0) { flag = false; break; } if( flag) System.out.println(“Prime Number”); else System.out.println(“Not Prime Number”); }

WAP to display an Fibonacci series Import java.util.*; Class Fibo { public static void main(string args[]) { int prev,next,sum,n; prev=next=1;

for( n=1; n<= 10 ; n++) { System.out.println (prev); sum=prev + next; prev=next; next =sum; }