Skip to main content

JAVA : W1-M1

Introduction to JAVA

Learning Objective

Welcome to the Task1 in Java.
In this Module let us solve some basic problems to check how Java works.
Make Sure that you learn the following concepts covered in this Module:
  • Data Types in Java
  • Operators
  • Conditional Statements
  • Iterative Statements
  • Arrays
Before getting ahead make sure you install Java

Orientation Videos







Programs for your reference

1.//Example Code: Hello.java



/**

* The Hello implements an application

* that displays "Hello World!" to the standard output

*/



public class Hello

{



 public static void main(String[] args)

  {



  // Display "Hello World!"

  System.out.println("Hello World!");

 }

} 

2.
/Example Code: MaxApp.java



/**

* The MaxApp class implements an application

* that finds maximum of given three numbers

*/

class  MaxApp

{

 public static void main(String[] args)

 {

  int a=3, b=5, c=2, max=0;

  //else-if ladder

 

  if(a>=b && a>=c)

  {

   max=a;

   System.out.println(a+" is greatest of the 3numbers");

  }

  else if(b>=a && b>=c)

  {

          max=b;

   System.out.println(b+" is greatest of the 3numbers");

  }

  else

  {

   max=c;

   System.out.println(c+" is greatest of the 3numbers");

  }

  //while loop

  while(max>=0)

  {

   max--;

   System.out.println("Printing Max number of times");

  }

 }

}



//3.continue - break

public class ContinueBreak

{

 public static void main(String[] args)

  {        

    Loop1: for(int i=0; i<100 br="br" i="i">           {

       System.out.println(" ");

       if(i>=10)

          break;

       for(int j=0; j<100 br="br" j="j">       {

           System.out.print("* ");

           if(j == i)

           continue Loop1;

       }

                }

      System.out.println("Termination by break");

  }

}

Task Description

1.
a. Write a program that prints to the screen "Hello Java"
b. Print the "Hello Java" program in a loop for about 100 times
c. In Looping for the same 100 times, if a number is divisible by 10, then print "Hurray! Divisible by 10", else print "Hello Java"
2. Take input from the user by prompting him to enter a character. If the character is 'a' -'z' then capitalize the character and display to the screen. If user enters 'q' then quit.
3.Write a program that iterates over the first 500 natural numbers and write all the non-prime numbers to the console.
4. Write a program to read three values and then compare and swap them to be in descending or ascending order.
5. Write a program to calculate Addition, Subtraction Multiplication or Division based on the option provided.

Comments