0% found this document useful (0 votes)
2 views

Java Program No 3 and 4

The document contains two Java programs. The first program concatenates two strings provided as command line arguments, while the second program prompts the user for a lower and upper bound, allowing them to input integers within that range to calculate their sum. Both programs demonstrate basic Java syntax and user input handling.

Uploaded by

thejas0716
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java Program No 3 and 4

The document contains two Java programs. The first program concatenates two strings provided as command line arguments, while the second program prompts the user for a lower and upper bound, allowing them to input integers within that range to calculate their sum. Both programs demonstrate basic Java syntax and user input handling.

Uploaded by

thejas0716
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Program No.

: 3 Write a program to concatenate two strings using command


line argument
class ConcatTwo
{
public static void main(String args[])
{
String s3;
s3 =args[0] + args[1];
System.out.println("The concatenated Strings = " + s3);
}
}

Program No.: 4 Write a program that asks the user for low and high integer in
a range of integers. The program then asks the user for integers to be added
up.
import java.util.Scanner;
public class Bounds
{
public static void main(String args[])
{
int lb, ub, isum = 0, i;
Scanner bo = new Scanner(System.in);
try
{
System.out.print("Enter lower bound: ");
lb = bo.nextInt();
System.out.print("Enter upper bound: ");
ub = bo.nextInt();
do
{
System.out.println("Enter numbers between the range and type 0 to stop:");
i = bo.nextInt(); if (i > lb && i < ub) isum += i;
}
while (i != 0);
System.out.println("The sum within the range is: " + isum);
}
catch (Exception e) {}
bo.close();
}
}

You might also like