Java Language Fundamentals

17 Comments

  • Thanks i greatly appriciate your site. It was down for a while last week. I was really upset. I am learning a lot from this site

  • Create a program that will display all odd letters in uppercase and all even letters lowercase in the alphabet using a loop. I have done Arrays but my prof. requires me not to declare values

    public class alpha{
    public static void main (String[] args) {

    String []apl = {“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”};

    for (int i = 0;i<26;i++)
    {
    if (i%2==0)
    System.out.print (apl[i].toUpperCase());
    else
    System.out.print (apl[i]);
    }

    }

    }

    • u can use ascii values
      like as for ‘a’ it is 97 now we have to print “c” 100 in lower case so we simply subtract 32 from ‘c’ ascii value to get ‘C’ next is ‘f’
      i.e 103 then 106 and so on.
      so logic could be like
      char[26] B;
      int[26] A;
      for(int i=0;i<26;i++)
      {
      A[i]=(i+97);
      }
      for(i=0;i<26;i++)
      {
      if(i%2==0||i==1)
      continue;
      else
      A[i]=A[i]-32;
      }

      for(int i=0;i<26;i++)
      {
      B[i]=Character.ParseChar(A[i]);
      }

      for(int i=0;i<26;i++)
      {
      System.out.println(B[i]);
      }

    • Hi this will help you what you need thank you

      public class Alpha{
      public static void main (String[] args) {

      String []apl = {“a”,”b”,”c”,”d”,”e”,”f”,”g”,”h”,”i”,”j”,”k”,”l”,”m”,”n”,”o”,”p”,”q”,”r”,”s”,”t”,”u”,”v”,”w”,”x”,”y”,”z”};

      for (int i = 0;i<26;i++)
      {
      System.out.print (apl[i].toUpperCase());
      i++;
      System.out.print (apl[i]);
      }

      }

      }

  • how to create a program of bubble sort which has names and marks of ten students in two arrays ‘names[] and marks[]’. You are required to sort these using ‘Bubble Sort’ algorithm.
    how to compare two neighboring objects, and to swap them if they are in the wrong order.

    The program should display both the raw and sorted contents of these arrays.
    Follow the steps below to implement the desired solution

    Steps to follow

    1. The program is to take the sorting parameter as command line argument. So
    1. If the command line argument is “names”, then the result should be sorted by names
    2. If the command line argument is “marks”, then the result should be sorted by marks. In this case you should also display the student’s rank

  • how to write the program for Employee Information System using the following methods

    An organization keeps pay scale data about each employee in its database. One of the purposes is to calculate income tax for each employee. Each Employee contains the following details:

    Employee Class

    Fields:

    Employee ID (int)

    Name (String)

    basic, hra, da (int)

    manager (Employee) – This field points to the manager for this employee. Each employee is assumed to report to only one manager.

    Constructors:

    Employee()

    Employee(int id, String name)

    Methods:

    get/set methods

    int calculateMonthlySalary()

    int calculateYearlySalary()

    int calculateIncomeTax()

    String toString()

    Manager Class

    Inherit a class Manager from Employee. It has the following additional information

    Fields:

    totalReportees (int) – Number of people who are reporting to this supervisor. This number can be anywhere between 0 and 5, both inclusive.

    Employee[] reportees – An array of Employee objects who report to this supervisor. Assume that each manager has a maximum of 5 direct reportees.

    Constructors:

    get/set methods

    Manager ()

    Manager (int id, String name)

    Methods:

    void addReportee(Employee)

    print() – To display the details of the manager

    print(level) – Print the reportees starting from this manager in a tree fashion. Prefix a ‘*’ to the name of the manager, if he has employees reporting to him

    Algorithms:

    monthly salary = (basic + hra + da)

    yearly salary = monthly salary * 12
    if (salary less than 100000)
    no tax
    if salary between 100000 – 500000
    tax is 20 % of amount above 100000
    if salary above 500000
    tax is 20 % of amount above 100000 and below 500000, and 40 % of amount above 500000

    If this manager already has 5 reportees, print an error message and do not add the new reportee.

    Remember that a Manager may have other managers as reportees, there by creating a tree-like employee reporting structure.

    Following is an example of output of printTree() method of Manager Class:

    If Paul and Henry report to Nick. John reports to Paul. Calvin and Smith report to Henry. Then the tree will look like:

    *Nick

    *Paul

    John

    *Henry

    Calvin

    Smith

    The setManager() method should also add the current object as a reportee for the manager

    print() – To display the details of the employee along with monthly and yearly salary

    • i am very new to this, can plz help me
      Write a program to take one command line argument.

      If the argument matches with a file name in the filesystem, display the size of the file
      If the argument matches with a directory name in the filesystem, display the names of the files contained in the directory
      Else display an error message

      Write a program Student.java.

      Student Class has the attributes: rollNumber, firstName, lastName, course, phoneNumber, hostel
      Dowload a csv file containing data about some students from here, using comma as the delimeter
      Read this file to populate the student objects and display the information formatted as follows:

      Roll Number: <rollnumber>

      Name: <firstname> <lastname>

      Course: <course>

      Phone Number: <phonenumber>

      Name of the Hostel: <hostel>

      ********************************************************************************************

      Roll Number: <rollnumber>

      Name: <firstname> <lastname>

      Course: <course>

      Phone Number: <phonenumber>

      Name of the Hostel: <hostel>

      ***************************************

  • someone help me….? Write a java program that prompts the user to enter the amount of rainfall recorded every month of the year and then display the output in reverse order. The user should get a prompt to enter the amount of rainfall as illustrated below: Enter Rainfall for Month 1: 50 Enter Rainfall for Month 2: 100 . . . . Enter Rainfall for Month 12: 67 The program should then give an output as illustrated below: Month 12:67 . . . . Month 2:100 Month 1:50 send to my email…
    jngari49@gmail.com

  • how to write program that flips a coin:

    a. One
    thousand times then prints out how many time you get tails and how many times
    you get heads.

    b. Continuously
    flipping the coin until a 1000 head count is achieved then print out how many
    times the coin has been flipped.

    c. Give the documentation for the applications that you
    have coded in (a) and (b)

    • /*
      Prime Numbers Java Example
      This Prime Numbers Java example shows how to generate prime numbers
      between 1 and given number using for loop.
      */

      public class GeneratePrimeNumbersExample {

      public static void main(String[] args) {

      //define limit
      int limit = 100;

      System.out.println(“Prime numbers between 1 and ” + limit);

      //loop through the numbers one by one
      for(int i=1; i < 100; i++){

      boolean isPrime = true;

      //check to see if the number is prime
      for(int j=2; j < i ; j++){

      if(i % j == 0){
      isPrime = false;
      break;
      }
      }
      // print the number
      if(isPrime)
      System.out.print(i + ” “);
      }
      }
      }

      /*
      Output of Prime Numbers example would be
      Prime numbers between 1 and 100
      1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

  • what situations we are using While and do-while loop please tell me. Tell me one situation where we have to use while or do-while loop without that we cant run our program please tell me that type of situations

Sponsors

Facebook Fans