Class Running Notes 14th Sept
Class Running Notes 14th Sept
*imp
Iterative Statements:
Statements.
i
thi
=>The following are some important iterative statements
from Java:
ipa
(a)while loop
(b)do-while loop
Ma
(c)for loop
(a)while loop:
sh
=>In while looping structure the condition is checked
syntax:
while(condition)
Ve
//loop_body
Flowchart:
i
thi
ipa
-----------------------------------------------------
(b)do-while loop:
Ma
=>In do-while loop the loop body is executed first
syntax:
do
nk
//loop_body
Ve
while(condition);
Flowchart:
i
thi
ipa
Note:
Ma
=>In realtime do-while loop is less used when compared
(c)for loop:
ate
same line
Ve
syntax:
for(Initialization;Condition;Incre/Decre)
//loop_body
}
Flowchart:
i
thi
ipa
Ma
=======================================================
sh
Ex-Program:
DemoString2.java
nk
package maccess;
import java.util.*;
public class DemoString2 {
Ve
i
thi
o/p:
ipa
java language programming
====Display in reverse=====
Assignment:
String or not?
nk
Ve
Note:
======================================================
faq:
i
thi
ASCII codes for LowerCase letters : 97 to 122
ipa
ASCII codes for Numbers( 0 to 9) : 48 to 57
Ma
Ex : DemoASCII.java
package maccess;
public class DemoASCII {
public static void main(String[] args) {
System.out.println("====UpperCase letters====");
sh
for(int i=65;i<=90;i++)
{
char ch = (char)i;//TypeCasting-ASCII(int) to char
ate
System.out.print(ch+" ");
}//end of loop
System.out.println("\n====LowerCase letters====");
for(int i=97;i<=122;i++)
{
nk
System.out.println("\n====Numbers(0 - 9)====");
for(int i=48;i<=57;i++)
{
char ch = (char)i;//TypeCasting-ASCII(int) to char
System.out.print(ch+" ");
}//end of loop
}
}
o/p:
====UpperCase letters====
ABCDEFGHIJKLMNOPQRSTUVWXYZ
====LowerCase letters====
abcdefghijklmnopqrstuvwxyz
====Numbers(0 - 9)====
i
thi
0123456789
====================================================
ipa
Assignment:(Soulution)
DemoString3.java
sh
package maccess;
import java.util.Scanner;
public class DemoString3 {
ate
{
char ch = str.charAt(index);
int k = (int)ch;//TypeCasting-char to ASCII(int)
if((k>=65 && k<=90) || (k>=97 && k<=122))
{
switch(ch)
{
case 'a':
case 'A':
System.out.println("char : "+ch);
System.out.println("Vowel...");
break;
case 'e':
case 'E':
System.out.println("char : "+ch);
System.out.println("Vowel...");
break;
case 'i':
case 'I':
System.out.println("char : "+ch);
System.out.println("Vowel...");
i
break;
thi
case 'o':
case 'O':
System.out.println("char : "+ch);
System.out.println("Vowel...");
ipa
break;
case 'u':
case 'U':
Ma System.out.println("char : "+ch);
System.out.println("Vowel...");
break;
default:
System.out.println("char : "+ch);
System.out.println("Consonent...");
}//end of switch
sh
}//end of if
else
{
ate
System.out.println("char : "+ch);
System.out.println("Others...");
}
}//end of if
nk
else
{
System.out.println("Invalid index...");
}
Ve
s.close();
}
o/p:
char : j
Consonent...
===================================================
i
thi
ipa
Ma
sh
ate
nk
Ve