Java

 Share more and more And comment for help




Only Java syllabus:          Click Here 

Important Books and the internet notes :

Download (20 MB)       Click Here   

ASSIGNMENT 1:                                    Download



Java Assignment 1


Java Workspace used for  making assignment contain all java files of the program below   

Download

 

Question 1: Write a program to check if a given number is Positive, Negative or Zero.

Code:

package first;

 

import java.util.Scanner;

 

public class firstcode {

        public static void main(String[] args)

           {

               int n;

               @SuppressWarnings("resource")

                     Scanner s = new Scanner(System.in);

               System.out.print("Enter the number you want to check:");

               n = s.nextInt();

               if(n > 0)

               {

                   System.out.println("The given number "+n+" is Positive");

               }

               else if(n < 0)

               {

                   System.out.println("The given number "+n+" is Negative");

               }

               else

               {

                   System.out.println("The given number "+n+" is neither Positive nor Negative ");

               }

           }

 

}

Output:

 


 













Question 2:

Code:

package second;

 

import java.util.Scanner;

 

public class secondcode {

       public static void main(String[] args)

    {

        int n;

        try (Scanner s = new Scanner(System.in)) {

                     System.out.print("Enter the number you want to check:");

                     n = s.nextInt();

              }

        if(n % 2 == 0)

        {

            System.out.println("The given number "+n+" is Even ");

        }

        else

        {

            System.out.println("The given number "+n+" is Odd ");

       }

    }

 

}

 

Output:


 

 

 











Question 3: Initialize two character variables in a program and display the characters in alphabetical order.Eg1) if first character is s and second is eO/P: e,s Eg2) if first character is a and second is eO/P:a,e  (If Statement)

Code:

package third;

 

public class thirdcode {

 

    public static void main (String[] args)

    {

        char item1='a';

        char item2='b';

        if (item1>item2)

            System.out.println(item2+" , "+item1);

      

        else

            System.out.println(item1+" , "+item2);

    }

 

}

 

 

Output:


 

 










 

Question 4: Initialize a character variable in a program and if the value is alphabet then print "Alphabet" if it’s a number then print "Digit" and for other characters print "Special Character" (If Statement)

Code:

public static void main(String args[])

{

    Scanner scanner=new Scanner(System.in);

    char char1 =scanner.next().charAt(0);

    if(char1>=48 && char1<=57)

    {

        System.out.print("char is Digit");

 

    }

    else if((char1>='a' && char1<='z')||(char1>='A' && char1<='Z'))

    {

        System.out.print("char is Alphabet");

    }

    else

    {

        System.out.print("char is special character");

 

    }

 

 

Output:


 

 

Question 5: Write a program to convert from upper case to lower case and vice versa of an alphabet and print the old character and new character as shown in example (Ex: a->A, M->m). (If Statement)

Code:

Lower To Upper

package fifth;

 

import java.util.Scanner;

 

public class fifthcode {

        public static void main(String[] input)

           {

               String strUpperstrLower;

               try (Scanner scan = new Scanner(System.in)) {

                           System.out.print("Enter one word/name in Lowercase : ");

                           strUpper = scan.nextLine();

                     }

              

              

               strLower = strUpper.toUpperCase();

               System.out.print("Equivalent Word/Name in Uppercase : " +strLower);

          

           }

}

Output:


 

 

Upper To Lower

package fifihcode;

 

import java.util.Scanner;

 

public class fifthrtwo {

        public static void main(String[] input)

           {

               String strUpperstrLower;

               try (Scanner scan = new Scanner(System.in)) {

                           System.out.print("Enter one word/name in Uppercase : ");

                           strLower = scan.nextLine();

                     }

              

               strUpper = strLower.toLowerCase();

               System.out.print("Equivalent Word/Name in Lowercase : " +strUpper);

           }

}

 

 

Output:

 


 

 










 

Question 6: Write a program to print the color name, based on color code. If color code in not valid then print "Invalid Code". R->Red, B->Blue, G->Green, O->Orange, Y->Yellow, W->White.( Switch Statement)

Code:

import java.util.Scanner;

 

public class sixthcode {

 

    public static void main(String[] args)

    {

        try (Scanner colour = new Scanner(System.in)) {

                     System.out.print("Enter the character(R/B/G/O/Y/W): ");

      char clr = colour.next().charAt(0);

      switch(clr)

      {

                        case 'R':

                            System.out.println("Red");

                            break;

                        case 'B':

                            System.out.println("Blue");

                            break;

                        case 'G':

                            System.out.println("Green");

                            break;

                        case 'O':

                            System.out.println("Orange");

                            break;

                        case 'Y':

                            System.out.println("Yellow");

                            break;

                        case 'W':

                            System.out.println("White");

                            break;

                        default:

                            System.out.println("Invalid Code");

                            break;

      }

              }

    }

 

}

       Output:

 














 

Question 7: Write a program to print numbers from 1 to 10 in a single row with one tab space.( For Loop)

Code:

package seventh;

 

public class seventhcode {

 

    public static void main(String[] args)

    {

                 for(int i = 1; i <= 10; i++)

                 {

                       System.out.println(i);

                  }

     }

 

}

output:


 

 

 









 

Question 8: Write a program to print even numbers between 23 and 57, each number should be printed in a separate row. ( For Loop)

Code:

package eight;

 

public class eighthcode {

       public static void main(String[] args)

    {

        System.out.println("Even Numbers between 23 and 57");

        for(int i=23;i<=57;i++){

            if(i%2==0){

                System.out.println(i);

            }

        }

       

     }

}

 

 

Output:


 

 

 

 

 

 







Question 9: Write a program to check if a given number is prime or not. ( For Loop)

Code:

package ninth;

 

import java.util.Scanner;

 

public class ninthcode {

        public static void main(String args[])

          {         

              int temp;

              boolean isPrime=true;

              Scanner scannew Scanner(System.in);

              System.out.println("Enter any number:");

              //capture the input in an integer

              int num=scan.nextInt();

               scan.close();

              for(int i=2;i<=num/2;i++)

              {

                  temp=num%i;

                 if(temp==0)

                 {

                    isPrime=false;

                    break;

                 }

              }

              //If isPrime is true then the number is prime else not

              if(isPrime)

                 System.out.println(num + " is a Prime Number");

              else

                 System.out.println(num + " is not a Prime Number");

          }

}

Output:

























Question 10: Write a program to print prime numbers between 10 and 99. ( For Loop)

Code:

package tenth;

 

public class tenth {

       public static void main (String[] args)

          {         

              int i =0;

              int num =0;

              //Empty String

              String  primeNumbers = "";

 

              for (i = 10; i <= 99; i++)        

              {                     

                 int counter=0;   

                 for(num =inum>=1; num--)

                {

                    if(i%num==0)

                   {

                     counter = counter + 1;

                   }

                }

                if (counter ==2)

                {

                   //Appended the Prime number to the String

                   primeNumbers = primeNumbers + i + " ";

                }   

              }    

              System.out.println("Prime numbers from 10 to 99 are :");

              System.out.println(primeNumbers);

          }

 

}

Output:



















SYLLABUS (Detailed Contents): This is not issued by PTU.


Unit – I
Introduction to OOP, procedural programming language and object-oriented language, principles of OOP, applications of OOP, history of java, java features, JVM, program structure. Variables, primitive data types, identifiers, literals, operators, expressions, precedence rules and associativity, primitive type conversion and casting, the flow of control.

Unit – II
Classes and objects, class declaration, creating objects, methods, constructors and constructor overloading, garbage collector, the importance of static keyword and examples, this keyword, arrays, command-line arguments, nested classes.

Unit – III
Inheritance, types of inheritance, super keyword, final keyword, overriding an abstract class. Interfaces, creating the packages, using packages, the importance of CLASSPATH, and java.lang package. Exception handling, the importance of try, catch, throw throws, and finally block, user-defined exceptions, Assertions.

Unit – IV
Multithreading: introduction, thread life cycle, creation of threads, thread priorities, thread synchronization, communication between threads. Reading data from files and writing data to files, random access file

Unit – V
Applet class, Applet structure, Applet life cycle, sample Applet programs. Event handling: event delegation model, sources of event, Event Listeners, adapter classes, inner classes

Unit – VI
AWT: introduction, components and containers, Button, Label, Checkbox, Radio Buttons, List Boxes, Choice Boxes, Container class, Layouts, Menu and Scrollbar






Comments

Popular posts from this blog

AMCAT

all question papers second (2) semester

Operating Systems Lab