Using loop and a half repetition control to test terminating the loop after execution loop body in while loop. We learned and took an example of while statement however, loop and a half repetition enables us to test terminating loop in the middle of loop body. This is an example of a java program which asks user to enter name and if the name length is less than or equal one character will display an error message.
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Wednesday, January 11
Wednesday, December 28
Loop the for and Nested-for statements - An example code of Java to multiply numbers
The for and Nested-for statements can be gathered in multiply way, it is usually building the for statement into another for statement in the case of ( Nested-for statements ), but in Syntax for the for statement it is easier to use and initialize or add increment as follows.
.
for( initialization; boolean expression; increment, decrement or update)
{
Statement here .......
}
Thursday, December 22
Syntax " for " and " if " statements - Java tutorials with a simple program
Today we are going to discuss for statement in Java syntax. With our code we are going to write it asks the user to enter multiply values ( inputs ) as much as the user wants, then program compares among these values and shows bigger, smaller and numbers of numbers that which are bigger than number 50 " for instant". Note: Our program uses console " Standard inputs and outputs".
Sunday, December 18
Syntax for Nested-if statement and Implement repetition control by while statement
Today we are going to use syntax for Nested-if statement in this case you can use it in any other way that allows you to write the main purpose of your program or portion of a program. If we want to use any other loop inside the code to control its destiny, because it is important to determine and terminate loop repetition at specific time. First of all we look at a syntax of Nested-if statements as this example.
if ( grade >= 90 )
System.out.println("A");
else if ( grade >= 80 )
System.out.println("B");
else if ( grade >= 50 )
System.out.println("C");
else
System.out.println("failed");
System.out.println("A");
else if ( grade >= 80 )
System.out.println("B");
else if ( grade >= 50 )
System.out.println("C");
else
System.out.println("failed");
Easy and enjoyable! We used Standard outputs to show results by (System.out), Also there is another option by using GUI outputs or input, however. To make it clear let's write it as a completed code. The program asks the user to input grade and displays results in Standard input and output ( Standard input or output it also named Console ).
Tuesday, December 13
Syntax for using switch and while statements together - Loop, Repetition Statements in Java
Today we are going to explain switch and while statements, but by using standard input, ouput and Scanner object that can be found in java.util package. Quite simple with practicing to know how switch statement works in some case. Let,s take code an example which asks the user to enter the number of the month then will show an output with its name.
Code is explained in it and I will clarify while and switch statements as follows:
We used while to tell the loop to be 12 times only if the number is invalid until it get the true value from switch statement which has true values consist of 1 to 12 with names, that is. We used break to termenate or in other meaning escape if this value is true.
/* This is our simple program, and we
* write description text here allows with names
* or any related details about the programe
* You_Java.java
*/
* write description text here allows with names
* or any related details about the programe
* You_Java.java
*/
Tuesday, November 29
GUI Input and output with JOptionPane - Java Tutorial
Analogous to Standard input and output, This is another easy way to provide GUI input and output based on message dialog or ( prompt ) by using JOptionPane class as the same with the following example to show message dialog.
JOptionPane.showMessageDialog(null, "Welcome to Java");
There are two arguments 1- JOptionPane.showMessageDialog for the class and 2- welcome to Java which appears in the dialog message, null means to put the message dialog in the center of the screen.
Standard Input , Output , Scanner class in Java to read strings
We use System.in to get input data from users to the program and it calls Standard input, as the same with this System.out which is Standard output to display or print information in console input. Scanner class from the package java.util allows us to achieve multiple input routines of string values only and the numerical values have the same but with a little difference we'll talk about it in other side.
This is an example for the standard input by using a Scanner object.
Friday, November 18
Comments in java codes - Java programming language
Comments are considered as a part of the java program components which allow to the programmer to describe some information about the program. It comes at the top like this one /* This is one line of comments */ , another example
/** This is another example
* with length as the programmer wants to describe
* or the name of the program
* Develop3.java
* Author: Developer Jo
* Develop3.java
* Author: Developer Jo
* A first program of a developer to improve programming skills and so.
* The description may range from short to long and very detailed description.
* The description may range from short to long and very detailed description.
* We can also call these comments at the beginning of methods like this example
* header comments.
* header comments.
*/
Subscribe to:
Posts (Atom)