SlideShare uma empresa Scribd logo
1 de 2
I enjoyed writing this sample code. With every DQ and weekly readings I learn more
about Java programming and I am finally starting to see the light. Some aspects of Java
programming are still a struggle for me like class and method, but I am working through
my understanding of these concepts. I do like the fact that NetBeans implies where the
errors exist and what is expected. I was unsure how to write the pseudocode for this
sample program because it appeared to be straightforward. With that said, I just used a
simple and short pseudocode that states exactly what the program will do when input of
a four-digit year is entered by the user.


Pseudocode
*** Program LeapYear
    1     prompt user to input a four-digit year using the IF ELSE conditional statement
    2     if user inputs a valid year, display “is a leap year”
    3     ELSE
    4     if user inputs an invalid year, display “is NOT leap year”
End Program


Here is my code and it is working.

package LeapYear;
/*
 * Prompt the user to enter a four-digit year. Using the IF ELSE conditional statement
print if it is a leap year or not.
 *
 * For example:

* If the user enters 1990, Display year 1990 is not a leap year
* If user input is 2000, display year 2000 is a leap year, etc.
*
*/

import java.util.Scanner;

class leapyear {

  public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     //
    // Read string input for a four-digit year
    //
     System.out.println("Please input a four-digit year");
     int input = in.nextInt();
int remainder = (input % 4);
    int century = (input % 100);

    if (remainder == 0) {
          if (century % 100 == 0) {
              System.out.println("The year: " + input + " is a leap year");
          }
          else {
              System.out.println("The year: " + input + " is NOT leapyear");
                 }
          }

Output 1:

Please input a year
1990
The year: 1990 is NOT leapyear
BUILD SUCCESSFUL (total time: 11 seconds)

Output 2:

Please input a year
2000
The year: 2000 is a leapyear
BUILD SUCCESSFUL (total time: 4 seconds)

Mais conteúdo relacionado

Destaque (7)

GAD 2015
GAD 2015GAD 2015
GAD 2015
 
utkarsh new cv
utkarsh new cvutkarsh new cv
utkarsh new cv
 
Mapa conceptual gestión de proyectos
Mapa conceptual gestión de proyectosMapa conceptual gestión de proyectos
Mapa conceptual gestión de proyectos
 
3
33
3
 
sarida scott_resume landscape
sarida scott_resume landscapesarida scott_resume landscape
sarida scott_resume landscape
 
+2 B&W
+2 B&W+2 B&W
+2 B&W
 
รายรับรายจ่าย ตุลาคม
รายรับรายจ่าย ตุลาคมรายรับรายจ่าย ตุลาคม
รายรับรายจ่าย ตุลาคม
 

Semelhante a Week3 dq4

JavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdfJavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdfSathwika7
 
Java programming: Elementary practice
Java programming: Elementary practiceJava programming: Elementary practice
Java programming: Elementary practiceKarwan Mustafa Kareem
 
2.3.tarek
2.3.tarek2.3.tarek
2.3.tarekafacct
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1Ankit Gupta
 
Solutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitchSolutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitchAlbern9271
 
Compose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdfCompose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdfKrishnaSoni261334
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the BasicsJussi Pohjolainen
 
Report in Java programming and SQL
Report in Java programming and SQLReport in Java programming and SQL
Report in Java programming and SQLvikram mahendra
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universitysjskjd709707
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6helpido9
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsshyaminfo04
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsash52393
 
Behavior Driven Development with Rails
Behavior Driven Development with RailsBehavior Driven Development with Rails
Behavior Driven Development with RailsMark Menard
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As CompDavid Halliday
 
Chapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.pptChapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.pptLisaMalar
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfKosmikTech1
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayKevlin Henney
 

Semelhante a Week3 dq4 (20)

Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
JavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdfJavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdf
 
Java programming: Elementary practice
Java programming: Elementary practiceJava programming: Elementary practice
Java programming: Elementary practice
 
2.3.tarek
2.3.tarek2.3.tarek
2.3.tarek
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
 
Solutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitchSolutions manual for absolute java 5th edition by walter savitch
Solutions manual for absolute java 5th edition by walter savitch
 
Compose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdfCompose Camp - Intro.pdf.pdf
Compose Camp - Intro.pdf.pdf
 
Programming with Java: the Basics
Programming with Java: the BasicsProgramming with Java: the Basics
Programming with Java: the Basics
 
Report in Java programming and SQL
Report in Java programming and SQLReport in Java programming and SQL
Report in Java programming and SQL
 
Cis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry universityCis355 a ilab 2 control structures and user defined methods devry university
Cis355 a ilab 2 control structures and user defined methods devry university
 
Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6Cis 355 i lab 1 of 6
Cis 355 i lab 1 of 6
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Devry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and stringsDevry cis 170 c i lab 5 of 7 arrays and strings
Devry cis 170 c i lab 5 of 7 arrays and strings
 
Behavior Driven Development with Rails
Behavior Driven Development with RailsBehavior Driven Development with Rails
Behavior Driven Development with Rails
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
Programming For As Comp
Programming For As CompProgramming For As Comp
Programming For As Comp
 
Chapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.pptChapter 1_Intro to Java.ppt
Chapter 1_Intro to Java.ppt
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Procedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went AwayProcedural Programming: It’s Back? It Never Went Away
Procedural Programming: It’s Back? It Never Went Away
 

Mais de amaxwell2012 (9)

Week3 dq1
Week3 dq1Week3 dq1
Week3 dq1
 
Week2 dq4
Week2 dq4Week2 dq4
Week2 dq4
 
Week2 dq3
Week2 dq3Week2 dq3
Week2 dq3
 
Week2 dq2
Week2 dq2Week2 dq2
Week2 dq2
 
Week1 dq5
Week1 dq5Week1 dq5
Week1 dq5
 
Week1 dq3
Week1 dq3Week1 dq3
Week1 dq3
 
Week1 dq2
Week1 dq2Week1 dq2
Week1 dq2
 
Week 4 dq 4
Week 4 dq 4Week 4 dq 4
Week 4 dq 4
 
Week 4 dq 3
Week 4 dq 3Week 4 dq 3
Week 4 dq 3
 

Week3 dq4

  • 1. I enjoyed writing this sample code. With every DQ and weekly readings I learn more about Java programming and I am finally starting to see the light. Some aspects of Java programming are still a struggle for me like class and method, but I am working through my understanding of these concepts. I do like the fact that NetBeans implies where the errors exist and what is expected. I was unsure how to write the pseudocode for this sample program because it appeared to be straightforward. With that said, I just used a simple and short pseudocode that states exactly what the program will do when input of a four-digit year is entered by the user. Pseudocode *** Program LeapYear 1 prompt user to input a four-digit year using the IF ELSE conditional statement 2 if user inputs a valid year, display “is a leap year” 3 ELSE 4 if user inputs an invalid year, display “is NOT leap year” End Program Here is my code and it is working. package LeapYear; /* * Prompt the user to enter a four-digit year. Using the IF ELSE conditional statement print if it is a leap year or not. * * For example: * If the user enters 1990, Display year 1990 is not a leap year * If user input is 2000, display year 2000 is a leap year, etc. * */ import java.util.Scanner; class leapyear { public static void main(String[] args) { Scanner in = new Scanner(System.in); // // Read string input for a four-digit year // System.out.println("Please input a four-digit year"); int input = in.nextInt();
  • 2. int remainder = (input % 4); int century = (input % 100); if (remainder == 0) { if (century % 100 == 0) { System.out.println("The year: " + input + " is a leap year"); } else { System.out.println("The year: " + input + " is NOT leapyear"); } } Output 1: Please input a year 1990 The year: 1990 is NOT leapyear BUILD SUCCESSFUL (total time: 11 seconds) Output 2: Please input a year 2000 The year: 2000 is a leapyear BUILD SUCCESSFUL (total time: 4 seconds)