Skip to main content

Posts

Showing posts with the label Java Programs

Java Program to Reverse a String

There are 2 ways to reverse a string  String reversal without using function String reversal with function String reversal without using function package stringReversal; import java.util.Scanner; public class StringReversal { int stringLength; static String stringToReverse; String reversedString=""; public String stringReverse(String name) { stringLength = name.length(); for(int i=stringLength-1; i>=0;i--) { reversedString+=name.charAt(i); } return reversedString; } public static void main(String[] args) { StringReversal stringReversal = new StringReversal(); Scanner scanner = new Scanner(System.in); System.out.print("Enter the string to reverse :"); stringToReverse = scanner.nextLine(); System.out.println("Reversed String is :" +stringReversal.stringReverse(stringToReverse)); } } Output Enter the string to reverse :Make the string reversed Reversed String is :desrever gnirts eht ekaM String ...

Java Program to Add Two Numbers

Let us see different modes of adding 2 numbers. Below are the contents of this post write a java program to add two numbers with predefined values write a java program to add two numbers with user-entered values write a java program to add 2 numbers using function For in-depth knowledge about the below programs check below topics Java Identifiers Java Modifiers Data Types Write a java program to add two numbers with predefined values package addNumbers; public class SumOfTwoNumbersWithPredefinedValues { public static void main(String[] args) { int sumNumber1=25; int sumNumber2=13; System.out.println("Sum of two numbers is :" +(sumNumber1+sumNumber2)); } } Output Sum of two numbers is :38 Write a java program to add two numbers with user-entered values package addNumbers; import java.util.Scanner; public class SumOfTwoNumbersWithUserDefinedValues { public static void main(String[] args) { int sumNumber1; int sumNumber2; Scanner scann...