Question

(Fs ) -2 3-2 out prito Qu.5 Write a java program that will accept any mumber from the use and will returs whether the eatered
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans 4

the output will be

1 tiumes 1 followed by a new line

2 times 2 followed by a new line

3 times 3 followed by a new line

4 times 4 followed by a new line

5 times 5 followed by a new line

Explanation :- The print statement in the inner loop depend on the value of i of the outer loop. The inner loop will iterate until the value of i, which is incremented in the outer loop.

So for ,

1 st iteration value of i = 1 so inner loop will iterate 1 time and print the value of i and comes out of the inner loop and print the new line on the outer loop.

2nd iteration value of i = 2 so inner loop will iterate 2 time and print the value of i twice and comes out of the inner loop and print the new line on the outer loop.

Same logic follows untill the valkue of i is more than 5. When the value of i is more than 5 it comes out of the outer loop and hence the program execution is over.

Output Screen shot

public static void main (String args for(int 1 : 1; ǐ i++) 12 13 14 15 16 17 18 5; for (int j- 1; j <-i; j++)f System out.pri

-----------------------------------------------------------------------------------------------------------------------------

Ans 5

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
       // Using Scanner for Getting Input from User
Scanner in = new Scanner(System.in);
System.out.println("Enter any number");
int a = in.nextInt();
if(a % 2 == 0){
System.out.println("The entered number is Even");
} else {
System.out.println("The entered number is Odd");
}
   }
}

Output

8 import java.util.scanner; 9 public class Main public static void main (String // Using Scanner for Getting Input from User

--------------------------------------------------------------------------------------------------------------------------------------------------

Ans 6

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
       // Using Scanner for Getting Input from User
Scanner in = new Scanner(System.in);
System.out.println("Enter Number scored in Exam");
int a = in.nextInt();
if(a >= 60){
System.out.println("Pass");
} else {
System.out.println("Fail");
}
   }
}

output

8 import java.util.scanner; 9 public class Main public static void main (String args 12 13 14 15 16 // Using Scanner for Gett

Add a comment
Know the answer?
Add Answer to:
(Fs ) -2 3-2 out prito Qu.5 Write a java program that will accept any mumber...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a java program making use of methods that finds the smallest of any three numbers...

    Write a java program making use of methods that finds the smallest of any three numbers that the user inputs. You must use JoptionPane to input the three numbers. A first method must be called and used to develop logic to find the smallest of the three numbers. A second method must be used to print out that smallest number found.

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • Write a Java program that determines if a person hits the "Pick 3" loterry numbers. Have...

    Write a Java program that determines if a person hits the "Pick 3" loterry numbers. Have the program to randomly create a 3 digit lottery number. Have the user enter the number they will be playing and the results: (DO NOT USE ARRAYS or STRINGS) -If the user input matches the lottery number in the exact order, the award is $5Million. -If all the digits in the user input match all the digits in the lottery number, the award is...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • This Java program reads an integer from a keyboard and prints it out with other comments....

    This Java program reads an integer from a keyboard and prints it out with other comments. Modify the comments at the top of the program to reflect your personal information. Submit Assignment1.java for Assignment #1 using Gradescope->Assignemnt1 on canvas.asu.edu site. You will see that the program has a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same...

  • Question 4 (3 mark) : Write a Java program to ask the user to input an...

    Question 4 (3 mark) : Write a Java program to ask the user to input an integer number from the keyboard. The output should indicate whether it is positive, zero, or negative, an even number or an odd number. REQUIREMENTS • Your code should ask user to input an integer number, then decide its sign and parity based on this input. • Your code should use if-else statement. Your code must work exactly as the specification and the output should...

  • Today you are to write a Java program that will prompt for and read 2 words...

    Today you are to write a Java program that will prompt for and read 2 words of equal length entered by the user, and create a new word which contains the last letter of the 1st word, the last letter of the 2nd word, followed by the second to last character of the 1st word, followed by the second to last character of the 2nd word and so on. Be sure to use the same format and wording as in...

  • Need help with java programming. Here is what I need to do: Write a Java program...

    Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1.     The input and variable value file are both text files that will be specified in...

  • JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts...

    JAVA: (15 marks) Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element in the array between 0 and 49, then displays the corresponding element value. If the specified index is out of bounds, display an error message (e.g. "Out of Bounds") and ask the user to enter another index. Use a while loop that will keep prompting the user until a valid input is received. To handle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT