Computer Programming Lab(5).

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Computer Programming Lab 8.
CS110 Programming Language I Lab 10: Arrays I Computer Science Department Spring 2014.
Scanner Pepper With credits to Dr. Siegfried. The Scanner Class Most programs will need some form of input. At the beginning, all of our input will come.
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
TA: Nouf Al-Harbi NoufNaief.net :::
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Writing algorithms using the for-statement. Programming example 1: find all divisors of a number We have seen a program using a while-statement to solve.
LAB 10.
Computer Programming Lab(4).
Announcements Quiz 2 Grades Posted on blackboard.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Week 2 - Wednesday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
1 Fencepost loops “How do you build a fence?”. 2 The fencepost problem Problem: Write a class named PrintNumbers that reads in an integer called max and.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Lecture 3 Decisions (Conditionals). One of the essential features of computer programs is their ability to make decisions. Like a train that changes tracks.
***** SWTJC STEM ***** Chapter 3-1 cg 39 Math Class The Math class provides a convenient way to access higher math functions. The Math class is automatically.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
DT249-Information Systems Research Practice Programming Revision Lecture 2 Lecturer: Patrick Browne.
Mixing integer and floating point numbers in an arithmetic operation.
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java Variables, Types, and Math Getting Started Complete and Turn in Address/Poem.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Review :chapters What is an algorithm? A step by step description of how to accomplish a task. For example, Adding 3 numbers N1, N2 and N3 Add.
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 +
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Exercise 1 #include int main() { printf(“Hello C Programming!\n”); return 0; } 1.Run your Visual Studio 2008 or Create a new “project” and add.
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.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
Computer Programming Lab 6. Exercise 1 Sample Runs.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
Building Java Programs Chapter 4 Lecture 4-1: Scanner ; cumulative algorithms reading: 3.3 – 3.4, 4.2.
Introduction to programming in java
Reading Parameters CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D.
Chapter 2 Clarifications
CSC111 Quick Revision.
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
TemperatureConversion
CS 201 Lecture 7: John Hurley Summer 2012 Cal State LA.
Maha AlSaif Maryam AlQattan
Computer Programming Methodology Input and While Loop
Repetition.
Data types, Expressions and assignment, Input from User
TK1114 Computer Programming
SELECTION STATEMENTS (1)
Something about Java Introduction to Problem Solving and Programming 1.
INPUT STATEMENTS GC 201.
Introduction to Classes and Methods
Java Variables, Types, and Math Getting Started
L3. Necessary Java Programming Techniques
L3. Necessary Java Programming Techniques
class PrintOnetoTen { public static void main(String args[]) {
Building Java Programs
Week 4 Lecture-2 Chapter 6 (Methods).
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
Random Numbers while loop
CSS161: Fundamentals of Computing
PROGRAMMING ASSIGNMENT I
Computer Science Club 1st November 2019.
Validation We have covered one way to get user input, using Scanner to get it from the console We will soon cover at least one additional way to get.
Presentation transcript:

Computer Programming Lab(5)

Exercise 1 (Convert feet into meters) Write a program that reads a number in feet, converts it to meters, and displays the result. One foot is 0.305 meter. Here is a sample run:

Source code: package ex2_3; import java.util.Scanner; public class EX2_3 { public static void main(String[] args) { Scanner input = new Scanner (System.in); System.out.println("Enter a value in feet : "); double feet = input.nextDouble(); double meter = feet *0.305 ; System.out.println(feet+ " Feet is " + meter + " meter."); }

Output:

Exercise 2 (Financial application: calculate tips) Write a program that reads the subtotal and the gratuity rate, then computes the gratuity and total. For example, if the user enters 10 for the subtotal and 15% for gratuity rate, the program displays $1.5 as gratuity and $11.5 as total. Here is a sample run :

Source code: package ex2_5; import java.util.Scanner; public class EX2_5 { public static void main(String[] args) { // Read subtotal Scanner input = new java.util.Scanner(System.in); System.out.print("Enter subtotal and gratuity rate: "); double subtotal = input.nextDouble(); double rate = input.nextDouble(); double gratuity = subtotal * rate / 100; double total = subtotal + gratuity; System.out.println ("The gratuity is " + gratuity + " total is " + total); }

Output:

Exercise 3 (Swap two numbers) Write a program that swap two integers then displays them before and after swapping.

Output:

Source code: public class EX1 { public static void main(String[] args) { int num1 = 10; int num2 = 20; System.out.println("Before Swapping"); System.out.println("Value of num1 is :" + num1); System.out.println("Value of num2 is :" +num2); //swap the value int temp = num1; num1 = num2; num2 = temp; System.out.println("After Swapping"); }