[go: up one dir, main page]

0% found this document useful (0 votes)
7 views18 pages

Arunav Java Assigment

The document provides Java code examples demonstrating basic programming concepts such as printing a character array, reversing a string, and splitting a string into individual characters. It includes a main class with methods that utilize loops and conditionals. The examples illustrate the use of auto-suggestion and code refactoring techniques like renaming variables and methods.

Uploaded by

Arunav Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views18 pages

Arunav Java Assigment

The document provides Java code examples demonstrating basic programming concepts such as printing a character array, reversing a string, and splitting a string into individual characters. It includes a main class with methods that utilize loops and conditionals. The examples illustrate the use of auto-suggestion and code refactoring techniques like renaming variables and methods.

Uploaded by

Arunav Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Use java platform, create a test project, create a test class and run

it to see how you can use auto suggestion and auto fill
functionality . Try a simple program of code formatter and code
refactoring like
Renaming variables,method and classes . try a program which
contains at least if else condition and a loop

public class Main {


public static void main(String[] args) {
char[] name = {'A', 'r', 'u', 'n', 'a', 'v', ' ', 'P', 'a', 't', 'h', 'a', 'k'};

// Print the character array as a string


System.out.println(name);
}
}

//output

B.Write a programm to reverse the stirng

public class Main {


public static void main(String[] args) {
String original = "Arunav";

// Convert the string to a character array


char[] characters = original.toCharArray();

// Reverse the character array in place


int left = 0;
int right = characters.length - 1;
while (left < right) {
// Swap characters at left and right indices
char temp = characters[left];
characters[left] = characters[right];
characters[right] = temp;

// Move towards the center


left++;
right--;
}

// Convert the reversed character array back to a string


String reversed = new String(characters);

System.out.println("Reversed string: " + reversed);


}
}

C . Split the stirng

public class Main {


public static void main(String[] args) {
String number = "98765";

// Loop through each character in the string


for (int i = 0; i < number.length(); i++) {
// Access each character using charAt() method
System.out.println(number.charAt(i));
}
}
}

You might also like