6. Write a program in java to print a multiplication table from one to five using do-while loop?

class Table {                 public static void main(String args[])                 {                                 int c=1;                                 do                                 {                                                 System.out.println(1*c +"\t"+ 2*c +"\t"+ 3*c +"\t"+ 4*c +"\t"+ 5*c);                                                 c++;                                 }while(c<=10);                 } } class Table {                 public static void main(String args[])                 {                                 int r=0,c=0,s=0;                                 do                                 {                                                 r++;... Continue Reading →

Advertisements

Constant: –

Constant: - Constants in java refer to fixed values that do not change during the execution of the program. Java support five different type of constant. They are integer constant, real constant, character constant, string constant and backslash character constant. Integer constant: - An integer constant refer to a sequence of digits without any decimal... Continue Reading →

5. Write a program in java to calculate and print sum of all odd number from one to 25 using while statement?

class SumOdd {                 public static void main(String args[])                 {                                 int c=0,j=1;                                 while(j<=25)                                                 {                                                 c+=j;                                                 j+=2;                                                 }                                 System.out.println("Sum of Odd Number (1 to 25) = "+c);                 } }

Java program structure: –

Java program structure: - A java program may contain number of section. All the sections are optional except main method class. A java program may contain many classes of which only one class defines a main method. Classes contain data members and methods that operate on the data members of the class. Methods may contain... Continue Reading →

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: