English, asked by sweety1729, 9 months ago

public class test {
public static void main(String args[]) {
Integer intobi=Integer.valueof (args[args.length-1]);
int i = intobj.intValue();
if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i-1);
else
System.out. println(i-2);
}
}​

Answers

Answered by roshinir651
4

Answer:

what class you are studying and what you wrote i cant understand

Answered by poojan
38

Output: 1

Note: The question has missed the vital detail about on which output it should be checked. As it is a popular question, which often asked users to check for the argument passage '2', here we are passing it as an argument.

Given program:

public class test {

public static void main(String args[]) {

Integer intObj=Integer.valueOf(args[args.length-1]);

int i = intObj.intValue();

if(args.length > 1)

System.out.println(i);

if(args.length > 0)

System.out.println(i - 1);

else

System.out.println(i - 2);

}

Input:

2

Output:

1

Explanation:

When we pass '2' as an argument, which is the only argument, the statement args.length value will be 1 and the args array will be {2} (As only one argument is passed).

Integer intobj=Integer.valueof (args[args.length-1]);

Here, As args.length = 1 for the only argument that has been passed, args[1-1] will be args[0] and the element at the zeroth position in the args array is 2.

So, Integer.valueof (args[args.length-1]);  = 2 which will be stored in intobj, and in the next statement int i = intobj.intValue();, the 2 will be stored in i.

if(args.length > 1) is a false condition, as args.length=1 which is not greater than 1.

if(args.length>0)   is a TRUE condition, as args.length=1 which is greater than 0.

So, it prints i - 1 which means 2 - 1 = 1. So, 1 will be printed.

Therefore, 1 is the output of this program when '2' is passed as an input.

Learn more:

1. Write a java Program  to accept name, roll number and marks in three subjects for a student Calculate total  marks and percentage. Print name, roll number percentage Alo print pass or fail.

https://brainly.in/question/13075562

2. Write a java program to input name and mobile numbers of all employees of any office. Using "Linear Search", search array of phone numbers for a given "mobile number" and print name of employee if found, otherwise print a suitable message.

brainly.in/question/18217872

Similar questions